home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / world.t.Z / world.t / helper.c < prev    next >
C/C++ Source or Header  |  1989-03-04  |  28KB  |  1,262 lines

  1. #include <stdio.h>
  2. #include "parame.inc"
  3. #include "variab.h"
  4. #include "arrays.h"
  5. #include "qtext.inc"
  6. # ifdef OSK
  7. # include <modes.h>
  8. # endif OSK
  9.  
  10. #define abs(A) ((A < 0) ? -A : A)
  11.  
  12. #ifndef AMIGA
  13. # ifndef OSK
  14. #  define Q1TEXT    "/usr/games/lib/q1text.dat"
  15. # else OSK
  16. #  define Q1TEXT    "%s/q1text.dat"
  17. # endif OSK
  18. #endif
  19.  
  20. # ifdef OSK
  21. # define srand srandom
  22. # define rand random
  23.  
  24. extern char    *getenv ();
  25. extern char    *getlogin ();
  26. extern char    *malloc ();
  27. extern char    *gamesdir;
  28. # endif OSK
  29.  
  30. /* World C Version 1.00 copyright 1987 J.D.McDonald 
  31.    Use as you like for non-commercial purposes, but please
  32.    leave this note, and document any changes you make as yours */
  33.  
  34. static int      start = 0;
  35. int             q1text_dat;
  36. # ifdef OSK
  37. static char    *q1text_fn = NULL;
  38. # endif OSK
  39. static int      debugflg = 1;
  40. static char     filenm[] = "world.sav";
  41.  
  42. static short    buffer[512];
  43. static long     filepos, oldpos;
  44.      
  45.  
  46. speak(point)
  47.     int             point;
  48. {
  49.     /* 
  50.      * this is the main routine to output text from the data file the word
  51.      * rtext(point) points to the proper record in the file  
  52.      */
  53.     int             i, bi, t, kk;
  54.     long            z;
  55.  
  56.     if (start == 0) {
  57.     start += 1;
  58.     oldpos = -1;
  59. #ifndef AMIGA                     /* q1text.dat already opened in wbstuff.c */
  60. # ifndef OSK
  61.     q1text_dat = open(Q1TEXT, 0);
  62. # else OSK
  63.     if (!q1text_fn)
  64.         if (!(q1text_fn = malloc (strlen (gamesdir) + 40)))
  65.             exit (207);
  66.         else
  67.             sprintf (q1text_fn, Q1TEXT, gamesdir);
  68.     q1text_dat = open(q1text_fn, S_IREAD);
  69. # endif OSK
  70. #endif
  71.       
  72.     }
  73.     z = (long) ((unsigned long) rtext[point]);
  74.     filepos = z * 2 & ~1023l;
  75.     if (filepos != oldpos) {
  76.     oldpos = filepos;
  77.     lseek(q1text_dat, filepos, 0);
  78.     read(q1text_dat, buffer, 512*sizeof(short));
  79.     }
  80.     bi = z & 511;
  81.     do {
  82.     kk = 0;
  83.     while (1) {
  84.         if (bi == 512) {
  85.         oldpos += 1024;
  86.         lseek(q1text_dat, oldpos, 0);
  87.         read(q1text_dat, buffer, 512*sizeof(short));
  88.         bi = 0;
  89.         }
  90.         t = buffer[bi];
  91.             z++;
  92.             bi++;
  93.  
  94.         if (t < 0) {
  95.         t = -t;
  96.         outst2[kk++] = t & 127;
  97.         outst2[kk++] = t >> 8;
  98.         } else {
  99.         outst2[kk++] = (t % 32) + 96;
  100.         outst2[kk++] = ((t >> 5) % 32) + 96;
  101.         outst2[kk++] = t / 1024 + 96;
  102.         if (outst2[kk - 3] == '{') {
  103.             kmax = kk - 4;
  104.                 break;
  105.         } 
  106.         }
  107.         if (outst2[kk - 2] == '{') {
  108.                 kmax = kk - 3;
  109.         break;
  110.         } else if (outst2[kk - 1] == '{') {
  111.             kmax = kk - 2;
  112.         break;
  113.         }
  114.     }
  115.     for (i = 0; i <= kmax; i++) {
  116.         if (outst2[i] == '`')
  117.         outst2[i] = ' ';
  118.         if (outst2[i] == '|')
  119.         outst2[i] = '.';
  120.     }
  121.     if (wwflag == 0)
  122.         linout(outst2, kmax + 1);
  123.     } while (z < rtext[point + 1]);
  124. }
  125.  
  126. vlocat(i, h)
  127.     int             i, h;
  128. {
  129.     int             k, p, r, nowir, xloc, xturn;
  130.     /*
  131.      * code for "l" or "locate"  but NOT "look" gtext(2) points to short
  132.      * descriptions in the location area of the text file, while gtext(1)
  133.      * points to the long ones  
  134.      */
  135.  
  136.     if (brfflg == 2 || i == 1 || ((locdat[loc] & 16384) == 0
  137.                   && brfflg != 0) || (loc >= 101 && loc <= 116))
  138.     xloc = loc + gtext[1];
  139.     else
  140.     xloc = loc + gtext[2];
  141.     speak(xloc);
  142.     if (loc == 89) {
  143.     if (easttm == 0) {
  144.         speak(372);
  145.         eastsc |= 1;
  146.     } else if (easttm > 0 && easttm <= 50) {
  147.         speak(373);
  148.         eastsc |= 2;
  149.     } else if (easttm == 51)
  150.         speak(374);
  151.     else {
  152.         speak(375);
  153.         eastsc |= 4;
  154.     }
  155.     }
  156.     xturn = turns % 100;
  157.     if (turns < 8)
  158.     xturn = 8;
  159.     if (h == 0)
  160.     return;
  161.     /* this section prints out the objects at "loc"  */
  162.     for (k = 1; k <= OBJMAX; k++) {
  163.     p = obimpr[k];
  164.     if (!((k <= MOVMAX && obloc[k] != loc) ||
  165.           (k > MOVMAX && (obw3[k] != loc && obw4[k] != loc)) ||
  166.           (k == HPUCK && loc == 38 && marflg[1]))) {
  167.         r = (p / 8) % 8;
  168.         if (r >= 1) {
  169.         if ((p & 1) == 1)
  170.             speak(odistb[k] + r);
  171.         }
  172.         if (!(obpprp[k] / 2048 == 0 && k != ZROBOT))
  173.         xcontn(k);
  174.     } continue;
  175.     }
  176.     /* standing on something?  */
  177.     if (spcloc == 1)
  178.     speak(212);
  179.     if (spcloc == 2) {
  180.     if (dirty == 0)
  181.         speak(509);
  182.     else
  183.         speak(510);
  184.     }
  185.     /* is the wire lying on the ground */
  186.     nowir = 1;
  187.     for (i = 0; i < 6; i++) {
  188.     if (wirelc[i] == loc)
  189.         nowir = 0;
  190.     }
  191.     if (nowir == 0)
  192.     speak(215);
  193.  
  194.     if ((loc == 76 || loc == 77 || loc == 79) && obloc[ZCAT] ==
  195.     80)
  196.     speak(280);
  197.     /* flowers following sun  */
  198.     if (loc == 86 && xturn > 6 && xturn < 69 && obimpr[ZSEED] > 4000)
  199.     speak(341);
  200.     /* vine describe   */
  201.     if (loc == 74 && obimpr[ZVINE] == 9) {
  202.     speak(339);
  203.     obimpr[ZVINE] = 8201;
  204.     } else if (loc == 74 && obimpr[ZVINE] == 8201)
  205.     speak(259);
  206. }
  207.  
  208. vinven()
  209. /* "inventory"  */
  210. {
  211.     int             carryn, wearn, i, k;
  212.  
  213.     carryn = 0;
  214.     wearn = 0;
  215.     if (wirelc[5] == 1000)
  216.     carryn = 1;
  217.     for (i = 1; i <= MOVMAX; i++) {
  218.     if (obloc[i] == 1000)
  219.         carryn = 1;
  220.     if (obloc[i] == 3000)
  221.         wearn = 1;
  222.     }
  223.     if (carryn == 1) {
  224.     speak(62);
  225.         xindnt += 2;
  226.     if (wirelc[5] == 1000)
  227.         speak(256);
  228.     for (k = 1; k <= MOVMAX; k++) {
  229.         if (obloc[k] != 1000)
  230.         continue;
  231.         speak(odistb[k]);
  232.         if (obpprp[k] / 2048 != 0)
  233.         xcontn(k);
  234.     }
  235.         xindnt -= 2;
  236.     }
  237.     if (wearn == 1) {
  238.     speak(63);
  239.         xindnt += 2;
  240.     for (k = 1; k <= MOVMAX; k++) {
  241.         if (obloc[k] != 3000)
  242.         continue;
  243.         speak(odistb[k]);
  244.         if (obpprp[k] / 2048 != 0)
  245.         xcontn(k);
  246.     }
  247.         xindnt -= 2;
  248.     }
  249.     if (carryn == 0 && wearn == 0)
  250.     speak(64);
  251.     nonext = 1;
  252. }
  253.  
  254. xcontn(k)                             /* RECURSIVE FUNCTION */
  255.     int             k;
  256. {
  257.     int             p, empty, k1;
  258.     /*
  259.      * list contents of a container 
  260.      * calls itself recursively to list things inside other containers
  261.      */
  262.  
  263.  
  264.            /* RECURSIVE FUNCTION */
  265.     if (k == LFUNNE || k == MFUNNE || k == RFUNNE)
  266.     return;
  267.     p = obimpr[k];
  268.     if ((p & 2) == 0 || (obpprp[k] & 128) == 0) {
  269.     empty = 1;
  270.     for (k1 = 1; k1 <= MOVMAX; k1++)
  271.         if (obloc[k1] == k + 2000)
  272.         empty = 0;
  273.     if (empty) {
  274.         xindnt += 2;
  275.         speak(odistb[k] + ((p / 512) % 8));
  276.         xindnt -= 2;
  277.     } else {
  278.         xindnt += 2;
  279.         speak(odistb[k] + ((p / 512) % 8) + 1);
  280.         xindnt += 2;
  281.         for (k1 = 1; k1 <= MOVMAX; k1++) {
  282.         if (obloc[k1] == k + 2000) {
  283.             speak(odistb[k1]);
  284.                  if (obpprp[k1] / 2048 != 0)
  285.                 xcontn(k1);
  286.                 }
  287.         }
  288.         xindnt -= 4;
  289.     }
  290.     } else if ((p & 2) != 0 && (obpprp[k] & 128) != 0 && prepdo == IN)
  291.     speak(386);
  292. }
  293.  
  294. dbg()
  295. {
  296.     char tmpstrq[80];
  297.     
  298.     if(debugflg == 0) return;
  299.     debugflg = 2;
  300.     printf(" loc is %5d \n", loc);
  301.     printf(" enter new loc ");
  302.     gets(tmpstrq);
  303. # ifdef OSK
  304.     cleareof (stdin);
  305. # endif OSK
  306.     sscanf(tmpstrq,"%d", &loc);
  307. }
  308.  
  309. scorng()
  310. {
  311.     int             result, i, q, v, l, n, plce, xplc;
  312.     result = 0;
  313.     if (loc >= 153)
  314.     return (0);
  315.     result = (diesc - 3) * 2;
  316.     if (result < 0)
  317.     result = 0;
  318.     if (cactsc == 1 || cactsc == 2)
  319.     result += 2;
  320.     if (cactsc == 3)
  321.     result += 4;
  322.     if ((eastsc & 1) != 0)
  323.     result += 2;
  324.     if ((eastsc & 2) != 0)
  325.     result += 2;
  326.     if ((eastsc & 4) != 0)
  327.     result += 2;
  328.     if(debugflg == 2) 
  329.         printf(" east+cact %5d out of 10\n",result);
  330.     for (i = 1; i <= MOVMAX; i++) {
  331.     q = obw4[i];
  332.     v = q / 4096;
  333.     l = q - v * 4096;
  334.     if (v == 0)
  335.         continue;
  336.         n = 0;
  337.     itsher(i, &plce);
  338.     if (i == GDISC) {
  339.         if (plce != 0 && rvtim == 2)
  340.         n = v;
  341.     } else if (l >= 4000 && l - 4000 != obloc[i])
  342.         n = v;
  343.     else if (l == 3000 && obloc[i] == 3000)
  344.         n = v;
  345.     else if (l == 1000 && (plce == 1 || plce == 3))
  346.         n = v;
  347.     else if (l == 3000 && (plce == 1 || plce == 3))
  348.         n = v / 2;
  349.     else if (l < 1000 && l == obloc[i])
  350.         n = v;
  351.     else if (l > 2000 && l < 3000 && obloc[i] == l) {
  352.         itsher((l - 2000), &xplc);
  353.         if (xplc > 0 && xplc <= 3)
  354.         n = v;
  355.     }
  356.         result += n;
  357.         if(debugflg == 2)printf("obj %5d %5d points out of %5d\n",i,n,v);
  358.     }
  359.     if (deadf)
  360.     result -= 5;
  361.     if (result < 0)
  362.     result = 0;
  363.     result *= 5;
  364.     return (result);
  365. }
  366.  
  367. getrob(don, doa)
  368.     int             don, doa;
  369. {
  370.     int             result, i;
  371.     /*
  372.      * search table for object return object number if found and unambiguous
  373.      * return 0 if not found return -1 if ambiguous  
  374.      */
  375.  
  376.     for (i = 1; i <= OBJMAX; i++) {
  377.     if (don != obnoun[i])
  378.         continue;
  379.     if ((doa == abs(obadjv[i])) || (doa == 0 && obadjv[i] < 0))
  380.         return (i);
  381.     else if (doa == 0 && obadjv[i] > 0)
  382.         result = -1;
  383.     else
  384.         result = 0;
  385.     }
  386.     return (result);
  387. }
  388.  
  389. # ifndef OSK
  390.     static  char    sstring[] =
  391.     "Your score is     out of a total of     in      turns.";
  392. # else OSK
  393. # define    SSTRING        "Your score is %d out of a total of %d in %d turns."
  394.     static char        sstring[128];
  395. # endif OSK
  396.     static  int     breakp[] = {0, 35, 70, 90, 130, 170, 210, 260, 330,
  397.                 380, 450, 900};
  398. scorpt(scor, mxsc)
  399.     int             scor, mxsc;
  400. {
  401.     char            cnum[4];
  402.     int             i;
  403.  
  404. # ifndef OSK
  405.     numcvt(scor, cnum);
  406.     sstring[14] = cnum[1];
  407.     sstring[15] = cnum[2];
  408.     sstring[16] = cnum[3];
  409.     numcvt(mxsc, cnum);
  410.     sstring[36] = cnum[1];
  411.     sstring[37] = cnum[2];
  412.     sstring[38] = cnum[3];
  413.     numcvt(turns, cnum);
  414.     sstring[43] = cnum[0];
  415.     sstring[44] = cnum[1];
  416.     sstring[45] = cnum[2];
  417.     sstring[46] = cnum[3];
  418.     linout(sstring, 54);
  419. # else OSK
  420.     sprintf (sstring, SSTRING, scor, mxsc, turns);
  421.     linout (sstring, strlen (sstring));
  422. # endif OSK
  423.     for (i = 0; i < 10; i++) {
  424.     if (scor >= breakp[i] && scor < breakp[i + 1])
  425.         break;
  426.     }
  427.     speak(481 + i);
  428.  
  429. }
  430.  
  431. numcvt(num, cnum)
  432.     int             num;
  433.     char           *cnum;
  434. {
  435.     int             lx, m;
  436.  
  437.     m = num / 1000;
  438.     lx = (m) ? '0' + m : ' ';
  439.     *cnum++ = lx;
  440.     m = (num / 100) % 10;
  441.     lx = (m == 0 && lx == ' ') ? ' ' : '0' + m;
  442.     *cnum++ = lx;
  443.     m = (num / 10) % 10;
  444.     lx = (m == 0 && lx == ' ') ? ' ' : '0' + m;
  445.     *cnum++ = lx;
  446.     m = num % 10;
  447.     *cnum = '0' + m;
  448. }
  449.  
  450. robdsc()
  451. {
  452.     int             rempty, lempty, k;
  453.  
  454.     if (obloc[ZROBOT] >= 90 && obloc[ZROBOT] <= 95)
  455.     speak(gtext[1] + obloc[ZROBOT]);
  456.     else
  457.     speak(226 + obloc[ZROBOT]);
  458.     rempty = 1;
  459.     lempty = 1;
  460.     for (k = 1; k <= MOVMAX; k++) {
  461.     if (obloc[k] == 2000 + ZROBOT)
  462.         rempty = 0;
  463.     if (obloc[k] == obloc[ZROBOT] && k != ZROBOT)
  464.         lempty = 0;
  465.     }
  466.     if (rempty == 0) {
  467.     speak(odistb[ZROBOT] + 5);
  468.     for (k = 1; k <= MOVMAX; k++) {
  469.         xindnt += 2;
  470.         if (obloc[k] == 2000 + ZROBOT)
  471.         speak(odistb[k]);
  472.         xindnt -= 2;
  473.     }
  474.     }
  475.     if (lempty == 0) {
  476.     speak(350);
  477.     for (k = 1; k <= MOVMAX; k++) {
  478.         xindnt += 2;
  479.         if (k != ZROBOT && obloc[k] == obloc[ZROBOT])
  480.         speak(odistb[k]);
  481.         xindnt -= 2;
  482.     }
  483.     }
  484.     if (obloc[ZROBOT] == 90 && (obloc[ZORCHI] == 2000 + ZROBOT
  485.                 || obloc[ZFLYTR] == 2000 + ZROBOT))
  486.     speak(353);
  487. }
  488.  
  489.  
  490. endsl()
  491. {
  492. #ifdef AMIGA
  493.     ttclose();       /* dummy routine to maybe clear screen? */
  494. #endif
  495. }
  496.  
  497.  
  498. vdead()
  499. {
  500.     int             i;
  501.     /*
  502.      * "you're dead,fred" it is incumbent on the calling routine to get to
  503.      * where the body is supposed to lie, and to set oldloc and oldlc2 to
  504.      * ,usually, 0 this routine sets deadf to .true. and drops all his
  505.      * possessions where he is now 
  506.      */
  507.  
  508.     eattim = 0;
  509.     rdietm = 0;
  510.     deadf = 1;
  511.     for (i = 1; i <= MOVMAX; i++)
  512.     if (obloc[i] == 1000 || obloc[i] == 3000)
  513.         obloc[i] = loc;
  514.     if (loc < 153)
  515.     speak(55);
  516.     else
  517.     speak(552);
  518.     nonext = 1;
  519.     eolflg = 1;
  520.     spcloc = 0;
  521.     for (i = 0; i < 6; i++)
  522.     if (wirelc[i] == 1000)
  523.         wirelc[i] = loc;
  524.     if (wirelc[0] != obloc[ZWIRE])
  525.     return;
  526.     for (i = 0; i < 6; i++)
  527.     wirelc[i] = 0;
  528.     diesc += 1;
  529. }
  530.  
  531. itsher(objt, plce)
  532.     int             objt;
  533.     int            *plce;
  534. {
  535.     int             n1;
  536.     /*
  537.      * this subroutine tells if an object is either: being carried     plce=1
  538.      * being worn        plce=2 inside something being carried,and not hidden
  539.      * from view (3) at "loc" and not hidden  (4) inside something at loc (5) 
  540.      */
  541.  
  542.     *plce = 0;
  543.     if (objt <= MOVMAX) {
  544.     if (obloc[objt] == 1000)
  545.         *plce = 1;
  546.     else if (obloc[objt] == 3000)
  547.         *plce = 2;
  548.     else if (obloc[objt] == loc && (obimpr[objt] & 1) == 1)
  549.         *plce = 4;
  550.     else if (obloc[objt] > 2000 && obloc[objt] < 3000) {
  551.         n1 = obloc[objt] - 2000;
  552.         if (n1 <= MOVMAX) {
  553.         if ((obloc[n1] == 1000 || obloc[n1] == 3000)
  554.             && (obimpr[n1] & 2) == 0)
  555.             *plce = 3;
  556.         else if (obloc[n1] == loc && ((obimpr[n1] & 1) == 1)
  557.              && ((obimpr[n1] & 2) == 0))
  558.             *plce = 5;
  559.         else;
  560.         } else if ((obw3[n1] == loc || obw4[n1] == loc) &&
  561.                ((obimpr[n1] & 1) == 1) && ((obimpr[n1] & 2) == 0))
  562.         *plce = 5;
  563.         else;
  564.     } else;
  565.     } else if ((obw3[objt] == loc || obw4[objt] == loc) &&
  566.            ((obimpr[objt] & 1) == 1))
  567.     *plce = 4;
  568. }
  569.  
  570. burden(ncarrd, nweigh, kcarrd, kweigh)
  571.     int            *ncarrd, *nweigh, *kcarrd, *kweigh;
  572. {
  573.     int             i;
  574.     /*
  575.      * calculate weight and number of objects on adventurer and in knapsack  
  576.      */
  577.  
  578.  
  579.     *ncarrd = 0;
  580.     *nweigh = 0;
  581.     for (i = 1; i <= MOVMAX; i++) {
  582.     if (obloc[i] != 1000)
  583.         continue;
  584.     *ncarrd += 1;
  585.     *nweigh += obw3[i] / 256;
  586.     }
  587.     *kcarrd = 0;
  588.     *kweigh = 0;
  589.     for (i = 1; i <= MOVMAX; i++) {
  590.     if (i == ZKNAPS || obloc[i] != (2000 + ZKNAPS))
  591.         continue;
  592.     *kcarrd += 1;
  593.     *kweigh += obw3[i] / 256;
  594.     }
  595. }
  596.  
  597. getobj(don, doa)
  598.     int             don, doa;
  599. {
  600.     /*
  601.      * search table for object return object number if found and unambiguous
  602.      * return 0 if not found return -1 if ambiguous  
  603.      */
  604.  
  605.     int             result, i, g1, g2, ggg, ddd, sum;
  606.     int             aplce, bplce, cplce, dplce, fplce, gplce, mplce, nplce, oplce, pplce;
  607.     int             splce, tplce;
  608.     result = 0;
  609.     for (i = 1; i <= OBJMAX; i++) {
  610.  
  611.     if (don != obnoun[i])
  612.         continue;
  613.     if ((doa == abs(obadjv[i]) && doa != BEAUTI && doa !=
  614.          VENDIN) || (doa == 0 && obadjv[i] < 0)) {
  615.         result = i;
  616.         return (result);
  617.     } else if ((doa == 0 && obadjv[i] > 0) || (doa == VENDIN &&
  618.              don == MACHIN) || (doa == BEAUTI && don == BIRD)) {
  619.         if (don == FISH) {
  620.         if (obloc[CFISH] != 0)
  621.             result = CFISH;
  622.         else
  623.             result = DFISH;
  624.         } else if (don == PANTS) {
  625.         itsher(RPANT, &g1);
  626.         itsher(LPANT, &g2);
  627.         if (g1 != 0 && g2 == 0)
  628.             result = RPANT;
  629.         else if (g1 == 0 && g2 != 0)
  630.             result = LPANT;
  631.         else if ((wrdnum[0] == TAKE && prepdo == OFF) ||
  632.              wrdnum[0] == REMOVE) {
  633.             if (g1 == 2)
  634.             result = RPANT;
  635.             else
  636.             result = LPANT;
  637.         } else if (wrdnum[0] == DROP)
  638.             if (((g1 == 1) || (g1 == 3)) && g2 != 1 && g2 != 3)
  639.             result = RPANT;
  640.         if (((g2 == 1) || (g2 == 3)) && g1 != 1 && g1 != 3)
  641.             result = LPANT;
  642.         else
  643.             result = -1;
  644.         } else if (don == SHIRT) {
  645.         itsher(RSHIRT, &g1);
  646.         itsher(GSHIRT, &g2);
  647.         if (g1 != 0 && g2 == 0)
  648.             result = RSHIRT;
  649.         else if (g1 == 0 && g2 != 0)
  650.             result = GSHIRT;
  651.         else if ((wrdnum[0] == TAKE && prepdo == OFF) ||
  652.              wrdnum[0] == REMOVE) {
  653.             if (g1 == 2)
  654.             result = RSHIRT;
  655.             else
  656.             result = GSHIRT;
  657.         } else if (wrdnum[0] == DROP) {
  658.             if (((g1 == 1) || (g1 == 3)) && g2 != 1 && g2 != 3)
  659.             result = RSHIRT;
  660.             if (((g2 == 1) || (g2 == 3)) && g1 != 1 && g1 != 3)
  661.             result = GSHIRT;
  662.         } else
  663.             result = -1;
  664.         } else if (don == DOOR) {
  665.         if (loc == 41 || loc == 135)
  666.             result = MDOOR;
  667.         else if (loc == 85 || loc == 136)
  668.             result = GDOOR;
  669.         else if (loc == 47 || loc == 51)
  670.             result = RDOOR;
  671.         else if (loc == 165 || loc == 166)
  672.             result = ODOOR;
  673.         else if (loc == 173)
  674.             result = PDOOR;
  675.         else if (loc == 175)
  676.             result = BDOOR;
  677.         else
  678.             result = -1;
  679.         } else if (don == CARTRI) {
  680.         itsher(ZCART, &tplce);
  681.         itsher(CCART, &cplce);
  682.         if (tplce > 0 && cplce <= 0)
  683.             result = ZCART;
  684.         else if (tplce <= 0 && cplce > 0)
  685.             result = CCART;
  686.         else
  687.             result = -1;
  688.         } else if (don == PHOTOG) {
  689.         itsher(PPHOTO, &pplce);
  690.         itsher(MPHOTO, &mplce);
  691.         itsher(OPHOTO, &oplce);
  692.         itsher(APHOTO, &aplce);
  693.         itsher(FPHOTO, &fplce);
  694.         pplce = (pplce < 1) ? pplce : 1;
  695.         mplce = (mplce < 1) ? mplce : 1;
  696.         oplce = (oplce < 1) ? oplce : 1;
  697.         aplce = (aplce < 1) ? aplce : 1;
  698.         fplce = (fplce < 1) ? fplce : 1;
  699.         sum = pplce + mplce + oplce + aplce + fplce;
  700.         {
  701.             if (sum == 0)
  702.             result = 0;
  703.             else if (sum > 1)
  704.             result = -1;
  705.             else {
  706.             if (pplce != 0)
  707.                 result = PPHOTO;
  708.             if (mplce != 0)
  709.                 result = MPHOTO;
  710.             if (oplce != 0)
  711.                 result = OPHOTO;
  712.             if (aplce != 0)
  713.                 result = APHOTO;
  714.             if (fplce != 0)
  715.                 result = FPHOTO;
  716.             }
  717.         }
  718.         } else if (don == BIRD) {
  719.         if (loc == 65 || loc == 66)
  720.             result = RBIRD;
  721.         else if (loc == 78 || loc == 79)
  722.             result = XBIRD;
  723.         else if (loc == 77 || loc == 80)
  724.             result = YBIRD;
  725.         else if (loc == 75 || loc == 76)
  726.             result = ZBIRD;
  727.         else
  728.             result = 0;
  729.         } else if (don == BUTTON) {
  730.         if (loc == 146 || loc == 134)
  731.             result = -1;
  732.         else if (loc == 143)
  733.             result = RDBUTT;
  734.         else if (loc == 169)
  735.             result = GBUTTO;
  736.         else
  737.             result = 0;
  738.         } else if (don == CABLE || don == DISC) {
  739.         if (don == CABLE) {
  740.             ddd = DCABLE;
  741.             ggg = GCABLE;
  742.         } else {
  743.             ddd = BDISC;
  744.             ggg = GDISC;
  745.         }
  746.         itsher(ddd, &dplce);
  747.         itsher(ggg, &gplce);
  748.         if (dplce == 0 && gplce == 0)
  749.             result = 0;
  750.         else {
  751.             if (wrdnum[0] == DROP) {
  752.             if ((dplce == 1 || dplce == 3) && (gplce != 1 
  753.                                                                  && gplce != 3))
  754.                 result = ddd;
  755.             else if ((gplce == 1 || gplce == 3) && 
  756.                                                      (dplce != 1 && dplce != 3))
  757.                 result = ggg;
  758.             else
  759.                 result = -1;
  760.             } else if (wrdnum[0] == TAKE) {
  761.             if ((dplce == 4 || dplce == 5) && (gplce != 4 
  762.                                                                  && gplce != 5))
  763.                 result = ddd;
  764.             else if ((gplce == 4 || gplce == 5) &&
  765.                                                      (dplce != 4 && dplce != 5))
  766.                 result = ggg;
  767.             else
  768.                 result = -1;
  769.             } else {
  770.             if (gplce == 0 && dplce != 0)
  771.                 result = ddd;
  772.             else if (dplce == 0 && gplce != 0)
  773.                 result = ggg;
  774.             else
  775.                 result = -1;
  776.             }
  777.         }
  778.         } else if (don == MACHIN) {
  779.         if (loc == 153)
  780.             result = PMACH;
  781.         else if (loc == 156)
  782.             result = TMACH;
  783.         else if (loc == 158)
  784.             result = NMACH;
  785.         else if (loc == 160)
  786.             result = SMACH;
  787.         else if (loc == 162)
  788.             result = MMACH;
  789.         } else if (don == SLOT) {
  790.         if (loc == 146)
  791.             result = RSLOT;
  792.         else if (loc == 156)
  793.             result = TSLOT;
  794.         else if (loc == 158)
  795.             result = NSLOT;
  796.         else if (loc == 160)
  797.             result = SSLOT;
  798.         else if (loc == 162)
  799.             result = MSLOT;
  800.         } else if (don == COIN) {
  801.         if (loc < 153)
  802.             result = SCOIN;
  803.         else {
  804.             itsher(SCOIN, &splce);
  805.             itsher(BCOIN, &bplce);
  806.             itsher(CCOIN, &cplce);
  807.             itsher(NCOIN, &nplce);
  808.             itsher(PCOIN, &pplce);
  809.             pplce = (pplce < 1) ? pplce : 1;
  810.             nplce = (nplce < 1) ? nplce : 1;
  811.             cplce = (cplce < 1) ? cplce : 1;
  812.             bplce = (bplce < 1) ? bplce : 1;
  813.             splce = (splce < 1) ? splce : 1;
  814.             sum = pplce + nplce + cplce + bplce + splce;
  815.             if (sum == 0)
  816.             result = 0;
  817.             else if (sum > 1)
  818.             result = -1;
  819.             else {
  820.             if (splce != 0)
  821.                 result = SCOIN;
  822.             if (bplce != 0)
  823.                 result = BCOIN;
  824.             if (cplce != 0)
  825.                 result = CCOIN;
  826.             if (nplce != 0)
  827.                 result = NCOIN;
  828.             if (pplce != 0)
  829.                 result = PCOIN;
  830.             }
  831.         }
  832.         } else
  833.         result = -1;
  834.         return (result);
  835.     }
  836.     }
  837.     return (result);
  838. }
  839.     static  char    strng1[] = "    I can't do that to item    on your list.";
  840.     static  char    strng2[] = "    Item number    on your list is ambiguous";
  841.  
  842. cnvobj()
  843. {
  844.     char            cnum[4];
  845.     int             result, many, i, k, n, p, z;
  846.  
  847.     /*
  848.      * this routine searches the list of objects and compares with the list
  849.      * of d.o.'s if an object exists and is unambiguous it's entry in dobjs
  850.      * is replaced by its object number otherwise its entry in dobjs is set
  851.      * to zero the entries in dobsj are then squeezed up if the result was
  852.      * totally unambiguous cnvobj is .true. 
  853.      */
  854.  
  855.     result = 1;
  856.     n = 0;
  857.     if (allflg)
  858.     n = 1;
  859.     many = 0;
  860.     if ((butflg && dobjs[2] != 0) || ((!butflg) &&
  861.                       dobjs[1] != 0))
  862.     many = 1;
  863.     k = 0;
  864.     z = -1;
  865.     for (i = n; i < 12; i++) {
  866.     k += 1;
  867.     if (dobjs[i] == 0)
  868.         break;
  869.     p = getobj(dobjs[i], doadjs[i]);
  870.     if (p > 0) {
  871.         z += 1;
  872.         dobjs[z] = p;
  873.     } else if (p == 0) {
  874.         if (many == 1) {
  875.         numcvt(k, cnum);
  876.         strng1[28] = cnum[2];
  877.         strng1[29] = cnum[3];
  878.         linout(strng1, 44);
  879.         } else
  880.         speak(422);
  881.     } else {
  882.         result = 0;
  883.         if (many == 1) {
  884.         numcvt(k, cnum);
  885.         strng2[16] = cnum[2];
  886.         strng2[17] = cnum[3];
  887.         linout(strng2, 44);
  888.         } else
  889.         speak(70);
  890.         speak(250);
  891.     }
  892.     }
  893.     while (++z < 30)
  894.     dobjs[z] = 0;
  895.     return (result);
  896. }
  897.  
  898. getall()
  899. {
  900.  
  901.     int             temp[30], i, k, d, m;
  902.     /*
  903.      * routine to get "all" or "all but" objects it only works on moveable
  904.      * objects because the only verbs which call it work only on those
  905.      * objects (drop,take, put) 
  906.      */
  907.  
  908.     for (i = 0; i < 30; i++) {
  909.     temp[i] = dobjs[i];
  910.     dobjs[i] = 0;
  911.     }
  912.     k = 0;
  913.     for (i = 1; i <= MOVMAX; i++) {
  914.     itsher(i, &d);
  915.     if (d == 0)
  916.         continue;
  917.     for (m = 0; m < 30; m++)
  918.         if (temp[m] == i)
  919.         goto endloop;
  920.     if (k == 29) {
  921.         speak(106);
  922.         return;
  923.     }
  924.     dobjs[k++] = i;
  925. endloop:
  926.     ;
  927.     }
  928. }
  929.  
  930.  
  931. rdinit()
  932. {
  933.     long            t;
  934.     long            tloc;
  935.     long            time();
  936.     int             ti;
  937.     t = time(&tloc);
  938.     ti =( (int) t) & 32767;
  939.     srand(ti);
  940. }
  941.  
  942. qrand()
  943. {
  944.     return ((rand() & 16383) / 4);
  945. }
  946.  
  947.  
  948. pct(q)
  949.     int             q;
  950. {
  951.     int             j;
  952.  
  953.     j = rand();
  954.     return ((q * 327) > (j & 32767));
  955. }
  956.  
  957. yesx(spk)
  958.     int             spk;
  959. {
  960.     char            ans[90];
  961.     /* ask question, and wait for reply from him */
  962.  
  963.  
  964.     speak(spk);
  965.     more = 0;
  966.     while (1) {
  967.     linout("?", 2001);
  968.     gets(ans);
  969. # ifdef OSK
  970.     cleareof (stdin);
  971. # endif OSK
  972.     more = 1;
  973.     if (strcmp(ans, "Y") == 0 || strcmp(ans, "YES") == 0
  974.         || strcmp(ans, "y") == 0 || strcmp(ans, "yes") == 0)
  975.         return (1);
  976.     else if (strcmp(ans, "N") == 0 || strcmp(ans, "NO") == 0
  977.          || strcmp(ans, "n") == 0 || strcmp(ans, "no") == 0)
  978.         return (0);
  979.     else
  980.         speak(102);
  981.     }
  982. }
  983.  
  984. getln()
  985. {
  986.     /* write a prompt, then read a line from the terminal */
  987.  
  988.     int             i, lastpos;
  989.     linout("> ", 7001);
  990.  
  991.     gets(inbuf);
  992. # ifdef OSK
  993.     cleareof (stdin);
  994. # endif OSK
  995.     eolflg = 0;
  996.     lastpos = strlen(inbuf);
  997.     lastpos = (lastpos > 78) ? 78 : lastpos;
  998.     for (i = lastpos; i < 83; i++)
  999.     inbuf[i] = '.';
  1000.     more = 1;
  1001.     inbuf[127] = (char)lastpos;
  1002. }
  1003.  
  1004.  
  1005. carerr(x, z)
  1006.     int             x, z;
  1007. {
  1008.     /*
  1009.      * this nifty routine put a caret on the terminal at the indicated
  1010.      * position of a line and then outputs a message  
  1011.      */
  1012.     /* if not the first sentence on a line, rewrite line.  */
  1013.  
  1014.     if (clause != 1) {
  1015.     linout(" ", 1001);
  1016.     linout(inbuf, inbuf[127]);
  1017.     }
  1018.     if (x > 0) {
  1019.     xindnt = x;
  1020.     linout("^", 1);
  1021.     xindnt = 0;
  1022.     } else {
  1023.     if (clause != 1) {
  1024.         xindnt = lptr - 1;
  1025.         linout("*", 1);
  1026.         xindnt = 0;
  1027.         speak(423);
  1028.     }
  1029.     }
  1030.     speak(z);
  1031. }
  1032.  
  1033. linout(ustring, num)
  1034.     char           *ustring;
  1035.     int             num;
  1036.  
  1037. {
  1038.     int             num1, i;
  1039. # ifndef OSK
  1040.     char            buff[80];
  1041. # else OSK
  1042.     char            buff[256];
  1043. # endif OSK
  1044.     char           *cptr;
  1045.  
  1046.     cptr = buff;
  1047.     num1 = num % 1000;
  1048.     for (i = 0; i < xindnt; i++)
  1049.     *cptr++ = ' ';
  1050.  
  1051.     for (i = 0; i < num1; i++)
  1052.     *cptr++ = *ustring++;
  1053.  
  1054.     *cptr++ = '\0';
  1055.     if (num < 1000) {
  1056.         if(more == 19 && nomor == 0) {
  1057.             i = strlen(buff);
  1058.             for( ; i < 73; i++)
  1059.                buff[i] = ' '; 
  1060.             strcpy(&buff[73],"MORE");
  1061.             printf("%1s", buff);
  1062.             gets(buff);
  1063. # ifdef OSK
  1064.         cleareof (stdin);
  1065. # endif OSK
  1066.             more = 0;
  1067.         }
  1068.         else {
  1069.             printf("%1s\n", buff);
  1070.             more += 1;
  1071.         }
  1072.     }
  1073.     else
  1074.     printf("%1s", buff);
  1075. }
  1076.  
  1077.  
  1078. vsuspe(inout)
  1079.     int             inout;
  1080. {
  1081.     short            sbuffer[256];
  1082. # ifdef OSK
  1083.     char        fn[256], *user;
  1084. # endif OSK
  1085.     int             result, filedes, i, iret;
  1086.     short           *sbptr, *iptr;
  1087.     result = 0;
  1088.  
  1089. # ifdef OSK
  1090.     if (!(user = getlogin ()))
  1091.     if (!(user = getenv ("USER")))
  1092.         if (!(user = getenv ("LOGNAME")))
  1093.         return;
  1094.     sprintf (fn, "%s/%s", gamesdir, user);
  1095. # endif OSK
  1096.     if (inout != 1) {
  1097.     /* "suspend" or "save"  */
  1098.  
  1099. # ifndef OSK
  1100.     filedes = creat(filenm, 0600);
  1101. # else OSK
  1102.     filedes = creat(fn, S_IWRITE);
  1103. # endif OSK
  1104.     if (filedes == -1) {
  1105.         linout("I failed to create your save file.", 34);
  1106.         return (result);
  1107.     }
  1108.     sbptr = sbuffer;
  1109.     *sbptr++ = horflg;
  1110.     for (i = 0; i < 6; i++)
  1111.         *sbptr++ = wirelc[i];
  1112.     *sbptr++ = turns;
  1113.     *sbptr++ = loc;
  1114.     *sbptr++ = oldloc;
  1115.     *sbptr++ = oldlc2;
  1116.     *sbptr++ = brfflg;
  1117.     *sbptr++ = deadf;
  1118.     *sbptr++ = dirty;
  1119.     *sbptr++ = nonext;
  1120.     *sbptr++ = spcloc;
  1121.     *sbptr++ = fshlif;
  1122.     *sbptr++ = noshoe;
  1123.     *sbptr++ = daytim;
  1124.     *sbptr++ = martim;
  1125.     for (i = 0; i < 9; i++)
  1126.         *sbptr++ = marflg[i];
  1127.     *sbptr++ = oextim;
  1128.     *sbptr++ = rdietm;
  1129.     *sbptr++ = rvtim;
  1130.     *sbptr++ = gvtim;
  1131.     *sbptr++ = eattim;
  1132.     *sbptr++ = easttm;
  1133.     *sbptr++ = filmtm;
  1134.     *sbptr++ = screef;
  1135.     *sbptr++ = eastsc;
  1136.     *sbptr++ = cactsc;
  1137.     *sbptr++ = diesc;
  1138.     *sbptr++ = filmst;
  1139.     *sbptr++ = machst;
  1140.     *sbptr++ = dial1;
  1141.     *sbptr++ = dial2;
  1142.     *sbptr++ = dial1x;
  1143.     *sbptr++ = dial2x;
  1144.     *sbptr++ = bonus;
  1145.     *sbptr++ = jackpo;
  1146.     *sbptr++ = lpill;
  1147.     *sbptr++ = pbstat;
  1148.     *sbptr++ = decset;
  1149.     *sbptr++ = raset;
  1150.     *sbptr++ = dcombi;
  1151.     *sbptr++ = chaset;
  1152.     *sbptr++ = guardl;
  1153.         *sbptr++ = fimage;
  1154.     write(filedes, sbuffer, 64*sizeof(short));
  1155.     sbptr = sbuffer;
  1156.     iptr = locdat;
  1157.     for (i = 0; i <= LOCNUM; i++)
  1158.         *sbptr++ = *iptr++;
  1159.     write(filedes, sbuffer, 256*sizeof(short));
  1160.     sbptr = sbuffer;
  1161.     iptr = obimpr;
  1162.     for (i = 0; i <= OBJMAX; i++)
  1163.         *sbptr++ = *iptr++;
  1164.     write(filedes, sbuffer, 256*sizeof(short));
  1165.     sbptr = sbuffer;
  1166.     iptr = obloc;
  1167.     for (i = 0; i <= OBJMAX; i++)
  1168.         *sbptr++ = *iptr++;
  1169.     write(filedes, sbuffer, 256*sizeof(short));
  1170.     close(filedes);
  1171.     return (result);
  1172.     } else {
  1173.     /* "restore"    */
  1174.  
  1175. # ifndef OSK
  1176.     filedes = open(filenm, 0);
  1177. # else OSK
  1178.     filedes = open(fn, S_IREAD);
  1179. # endif OSK
  1180.     if (filedes == -1)
  1181.         goto lab1;
  1182.     iret = read(filedes, sbuffer, 64*sizeof(short));
  1183.     if (iret != 64*sizeof(short))
  1184.         goto lab1;
  1185.     sbptr = sbuffer;
  1186.     horflg = *sbptr++;
  1187.     for (i = 0; i < 6; i++)
  1188.         wirelc[i] = *sbptr++;
  1189.     turns = *sbptr++;
  1190.     loc = *sbptr++;
  1191.     oldloc = *sbptr++;
  1192.     oldlc2 = *sbptr++;
  1193.     brfflg = *sbptr++;
  1194.     deadf = *sbptr++;
  1195.     dirty = *sbptr++;
  1196.     nonext = *sbptr++;
  1197.     spcloc = *sbptr++;
  1198.     fshlif = *sbptr++;
  1199.     noshoe = *sbptr++;
  1200.     daytim = *sbptr++;
  1201.     martim = *sbptr++;
  1202.     for (i = 0; i < 9; i++)
  1203.         marflg[i] = *sbptr++;
  1204.     oextim = *sbptr++;
  1205.     rdietm = *sbptr++;
  1206.     rvtim = *sbptr++;
  1207.     gvtim = *sbptr++;
  1208.     eattim = *sbptr++;
  1209.     easttm = *sbptr++;
  1210.     filmtm = *sbptr++;
  1211.     screef = *sbptr++;
  1212.     eastsc = *sbptr++;
  1213.     cactsc = *sbptr++;
  1214.     diesc = *sbptr++;
  1215.     filmst = *sbptr++;
  1216.     machst = *sbptr++;
  1217.     dial1 = *sbptr++;
  1218.     dial2 = *sbptr++;
  1219.     dial1x = *sbptr++;
  1220.     dial2x = *sbptr++;
  1221.     bonus = *sbptr++;
  1222.     jackpo = *sbptr++;
  1223.     lpill = *sbptr++;
  1224.     pbstat = *sbptr++;
  1225.     decset = *sbptr++;
  1226.     raset = *sbptr++;
  1227.     dcombi = *sbptr++;
  1228.     chaset = *sbptr++;
  1229.     guardl = *sbptr++;
  1230.         fimage = *sbptr++;
  1231.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1232.     if (iret != 256*sizeof(short))
  1233.         goto lab1;
  1234.     sbptr = sbuffer;
  1235.     iptr = locdat;
  1236.     for (i = 0; i <= LOCNUM; i++)
  1237.         *iptr++ = *sbptr++;
  1238.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1239.     if (iret != 256*sizeof(short))
  1240.         goto lab1;
  1241.     sbptr = sbuffer;
  1242.     iptr = obimpr;
  1243.     for (i = 0; i <= OBJMAX; i++)
  1244.         *iptr++ = *sbptr++;
  1245.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1246.     if (iret != 256*sizeof(short))
  1247.         goto lab1;
  1248.     sbptr = sbuffer;
  1249.     iptr = obloc;
  1250.     for (i = 0; i <= OBJMAX; i++)
  1251.         *iptr++ = *sbptr++;
  1252.         close(filedes);
  1253.     result = 1;
  1254.     chaser = 0;
  1255.     linout(" ", 1);
  1256.     return (result);
  1257.     }
  1258. lab1:
  1259.     linout("Restore failed.", 15);
  1260.     return (result);
  1261. }
  1262.