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 / demons.c < prev    next >
C/C++ Source or Header  |  1989-03-04  |  9KB  |  441 lines

  1. #include "parame.inc"
  2. #include "variab.h"
  3. #include "arrays.h"
  4.  
  5. /* World C Version 1.00 copyright 1987 J.D.McDonald 
  6.    Use as you like for non-commercial purposes, but please
  7.    leave this note, and document any changes you make as yours */
  8.  
  9. mdemon()
  10. {
  11.  
  12.     int             qtim, z, i, kkwr;
  13.     /*
  14.      * subroutine to care for comings and goings of martians 
  15.      */
  16.  
  17.     qtim = (turns % 100) < 75;
  18.     /*
  19.      * the player must have entered mars once in the day and once at night,
  20.      * and then wait 4 turns before they come close 
  21.      */
  22.  
  23.     if (martim < 7) {
  24.     if (loc == 27 || loc == 50 || loc == 41) {
  25.         oldloc = 0;
  26.         speak(152);
  27.     }
  28.     if (loc >= 26 && loc <= 50) {
  29.         if (qtim && (martim == 0 || martim == 2))
  30.         martim |= 1;
  31.         if (!qtim && (martim == 0 || martim == 1))
  32.         martim |= 2;
  33.         if (martim >= 3)
  34.         martim += 1;
  35.     }
  36.     }
  37.     if (qtim)
  38.     return;
  39.     /*
  40.      * they will appear at once if he falls in their hockey rink 
  41.      */
  42.  
  43.     if (loc == 38 && !marflg[5]) {
  44.     marflg[5] = 1;
  45.     martim = 7;
  46.     speak(169);
  47.     return;
  48.     }
  49.     for (i = 0; i < 5; i++)
  50.     marflg[i] = 0;
  51.     z = (turns % 100);
  52.     /* wont come close if martim < 7 */
  53.  
  54.     if (martim < 7) {
  55.     if (loc != 51)
  56.         speak(141);
  57.     goto lab60;
  58.     }
  59.     if (z > 75 && z < 99)
  60.     marflg[4] = 1;
  61.     if (z > 76 && z < 98)
  62.     marflg[0] = 1;
  63.     if (z > 78 && z < 95)
  64.     marflg[3] = 1;
  65.     if (z > 78 && z < 96)
  66.     marflg[2] = 1;
  67.     if (z > 77 && z < 97 && obloc[HPUCK] == 38)
  68.     marflg[1] = 1;
  69.     /* announce the goings on of the martians */
  70.  
  71.     if (marflg[5] && z == 75 && loc != 38)
  72.     speak(154);
  73.     if (marflg[5] && z == 99 && loc != 38)
  74.     speak(155);
  75.     /* the first time they come close */
  76.  
  77.     if (!marflg[5] && loc < 51) {
  78.     marflg[5] = 1;
  79.     speak(142);
  80.     }
  81.     if (loc == 28) {
  82.     if (marflg[3])
  83.         speak(143);
  84.     } else if (loc >= 43 && loc <= 45) {
  85.     if (marflg[4])
  86.         speak(144);
  87.     }
  88.     /* at home */
  89.  
  90.     else if (loc == 42 || loc == 30) {
  91.     if (marflg[0]) {
  92.         if (!marflg[6] || pct(20)) {
  93.         speak(145);
  94.         marflg[6] = 1;
  95.         } else
  96.         speak(146);
  97.     }
  98.     }
  99.     /* the hockey game  */
  100.  
  101.     else if (loc == 29 || (loc >= 31 && loc <= 38)) {
  102.     if (marflg[1]) {
  103.         if (!marflg[7] || pct(20)) {
  104.         speak(147);
  105.         marflg[7] = 1;
  106.         } else
  107.         speak(148);
  108.     }
  109.     } else if (loc == 40) {
  110.     if (marflg[2])
  111.         speak(149);
  112.     } else;
  113.     if (((loc == 42 && marflg[0]) || (loc == 38)) && !deadf) {
  114.     /* oops! he ran inot one and got fried  */
  115.  
  116.     if (loc == 42)
  117.         speak(150);
  118.     if (loc == 38) {
  119.         if (marflg[1])
  120.         speak(151);
  121.         else
  122.         speak(171);
  123.         for (i = 32; i <= 37; i++)
  124.         locdat[i] |= 16384;
  125.     }
  126.     vdead();
  127.     oldlc2 = 0;
  128.     oldloc = 0;
  129.     }
  130.     /* move his belongings to the dump */
  131.  
  132. lab60:
  133.     for (i = 1; i <= MOVMAX; i++) {
  134.     if (obloc[i] == loc || (obloc[i] == 48 && loc == 49) || obloc[i] < 27 ||
  135.         obloc[i] > 50)
  136.         continue;
  137.     if (i == ZWIRE) {
  138.         if (obloc[i] == 1000 || wirelc[0] == 1000 || wirelc[5]
  139.         == 1000 || wirelc[0] == loc || wirelc[1] == loc
  140.         || wirelc[2] == loc || wirelc[3] == loc
  141.         || wirelc[4] == loc || wirelc[5] == loc)
  142.         continue;
  143.         obimpr[ZWIRE] = (obimpr[ZWIRE] & ~56) + 8;
  144.         /* ~56=177707 octal */
  145.  
  146.         for (kkwr = 0; kkwr < 6; kkwr++)
  147.         wirelc[kkwr] = 0;
  148.     }
  149.     if (obloc[i] >= 27 && obloc[i] <= 50)
  150.         obloc[i] = 40;
  151.     if (i == HPUCK)
  152.         obloc[i] = 38;
  153.     if (i == ZDIAMO) {
  154.         obimpr[i] = (obimpr[i] & ~56) + 8;
  155.         obloc[i] = 49;
  156.     }
  157.     if (i == RBOULD)
  158.         obloc[i] = 27;
  159.     }
  160.     return;
  161. }
  162.  
  163. wdemon()
  164. {
  165.     int             i, n, i2, vloc;
  166.     /*
  167.      * take care of playing out and taking in the wire take it in  
  168.      */
  169.  
  170.     if (wirelc[5] == 1000) {
  171.     for (i = 1; i <= 4; i++) {
  172.         n = 5 - i;
  173.         if (wirelc[n] == oldloc && wirelc[n - 1] == loc) {
  174.         wirelc[n] = 1000;
  175.         speak(216);
  176.         if (wirelc[1] == 1000 && obloc[ZWIRE] == 1000 && wirelc[0] == loc) {
  177.             for (i2 = 0; i2 < 5; i2++)
  178.             wirelc[i2] = 0;
  179.             speak(219);
  180.         }
  181.         return;
  182.         }
  183.     }
  184.     if (wirelc[1] == 1000 && wirelc[0] == oldloc && obloc[ZWIRE]
  185.         == loc) {
  186.         wirelc[0] = 1000;
  187.         speak(216);
  188.         return;
  189.     }
  190.     /* play it out  */
  191.  
  192.     if (loc >= 32 && loc <= 38) {
  193.         speak(257);
  194.         if (oldloc == 31 || oldloc == 32)
  195.         vloc = 32;
  196.         else
  197.         vloc = 37;
  198.         for (i = 0; i < 6; i++)
  199.         if (wirelc[i] == 1000)
  200.             wirelc[i] = vloc;
  201.         return;
  202.     }
  203.     for (i = 0; i < 4; i++) {
  204.         if (wirelc[i] == oldloc && wirelc[i + 1] == 1000) {
  205.         wirelc[i + 1] = loc;
  206.         speak(217);
  207.         return;
  208.         }
  209.     }
  210.     if (wirelc[0] == 1000 && obloc[ZWIRE] == oldloc) {
  211.         wirelc[0] = loc;
  212.         speak(217);
  213.         return;
  214.     }
  215.     /* out of wire   */
  216.  
  217.     if (wirelc[4] == oldloc) {
  218.         speak(218);
  219.         wirelc[5] = wirelc[4];
  220.         return;
  221.     }
  222.     } else;
  223. }
  224.  
  225.  
  226. timer(xloc)
  227.     int             xloc;
  228. {
  229.     int             bplce, cplce, gplce, iplce, objen, qq, i;
  230.  
  231.     /* prevent him from being outside the valley at sunset */
  232.  
  233.     if (loc <= 3 && loc * 15 < turns) {
  234.     speak(255);
  235.     oldlc2 = oldloc;
  236.     oldloc = loc;
  237.     loc += 1;
  238.     }
  239.     /*
  240.      * daytim=1 if it is intrinsically light here (i.e. lights are always on
  241.      * or it is outside and the sun is up or he is carrying sphere or bead  
  242.      */
  243.  
  244.     if ((locdat[loc] & 17) != 0 || ((locdat[loc] & 8) != 0
  245.                  && (turns % 100) < 75) || obloc[GSPHER] == 1000
  246.     || obloc[GSPHER] == loc || obloc[ZBEAD] == 1000 ||
  247.     obloc[ZBEAD] == loc)
  248.     daytim = 1;
  249.     else
  250.     daytim = 0;
  251.     /* he is killed if on tower in daytime  */
  252.  
  253.     if (loc == 49 && daytim == 1 && !deadf) {
  254.     speak(166);
  255.     oldlc2 = 0;
  256.     oldloc = 0;
  257.     loc = 48;
  258.     vdead();
  259.     }
  260.     /* announce rising and setting of both suns  */
  261.  
  262.     if ((locdat[loc] & 8) != 0) {
  263.     if (daytim == 0)
  264.         speak(124);
  265.     else if ((turns % 100) >= 72 && (turns % 100) < 75)
  266.         speak(125);
  267.     else if ((turns % 100) < 3 && turns > 4)
  268.         speak(126);
  269.     else;
  270.     }
  271.     /*
  272.      * check to see if he is not wearing shoes or boots if too long without
  273.      * them, he dies  
  274.      */
  275.  
  276.     if ((obloc[CSHOES] != 3000 && obloc[HBOOTS] != 3000) &&
  277.     !deadf && (loc != 16 && loc < 153)) {
  278.     noshoe -= 1;
  279.     if (noshoe == 0)
  280.         speak(99);
  281.     else if (noshoe < -6 && pct(10 * (-6 - noshoe))) {
  282.         speak(100);
  283.         vdead();
  284.     }
  285.     }
  286.     /* fish need water to live!  */
  287.  
  288.     if (obloc[DFISH] == 0) {
  289.     if (obloc[CFISH] != 16 && !(obloc[CFISH] == (2000 + PLBAG)
  290.                     && (((obimpr[PLBAG] / 512) % 8) == 5))) {
  291.         fshlif -= 1;
  292.         if (fshlif == 0) {
  293.         obloc[DFISH] = obloc[CFISH];
  294.         obloc[CFISH] = 0;
  295.         obimpr[CFISH] = 0;
  296.         obimpr[DFISH] = 137;
  297.         }
  298.     }
  299.     }
  300.     /* check on status of bug repellent  */
  301.  
  302.     if (obimpr[ZDEET] >= 4096)
  303.     obimpr[ZDEET] -= 4096;
  304.     /* check on radioactive exposure of film in camera  */
  305.  
  306.     itsher(ZBEAD, &bplce);
  307.     itsher(GSPHER, &gplce);
  308.     if (oextim < 8000) {
  309.     itsher(ICAMER, &iplce);
  310.     if (obloc[GSPHER] == obloc[ICAMER])
  311.         oextim += 1;
  312.     else {
  313.         if (iplce != 0 && gplce != 0)
  314.         oextim += 1;
  315.     }
  316.     if (obloc[ZBEAD] == obloc[ICAMER])
  317.         oextim += 7;
  318.     else {
  319.         if (iplce != 0 && bplce != 0)
  320.         oextim += 4;
  321.     }
  322.     }
  323.     /* check on radiation poisoning  */
  324.  
  325.     if (!deadf && bplce != 0 && obloc[ZBEAD] != 2000 + ZSINK) {
  326.     rdietm = (rdietm / 5) * 5;
  327.     rdietm += 5;
  328.     if (rdietm > 0 && (rdietm % 10) == 0)
  329.         speak(rdietm / 10 + 320);
  330.     } else {
  331.     rdietm -= 1;
  332.     if (rdietm <= 0)
  333.         rdietm = 0;
  334.     if (rdietm == 36)
  335.         speak(326);
  336.     if (rdietm == 24)
  337.         speak(327);
  338.     if (rdietm == 12)
  339.         speak(328);
  340.     }
  341.     /* check on changing of loc 89 */
  342.  
  343.     if (easttm == 1)
  344.     speak(376);
  345.     if (easttm == 15)
  346.     speak(377);
  347.     if (easttm == 50)
  348.     speak(378);
  349.     if (easttm >= 1 && easttm <= 50)
  350.     easttm += 1;
  351.     if (!deadf)
  352.     eattim += 1;
  353.     if (eattim == 170)
  354.     speak(367);
  355.     if (eattim == 240)
  356.     speak(368);
  357.     if (eattim == 270)
  358.     speak(369);
  359.     if (eattim == 300) {
  360.     speak(384);
  361.     vdead();
  362.     }
  363.     /* exposing the x-ray film  */
  364.  
  365.     itsher(ZCASSE, &cplce);
  366.     if (obloc[ZCASSE] == 2000 + ZRACK && obloc[ZBEAD] == 2000 + ZTRAY) {
  367.     objen = 0;
  368.     for (i = 0; i <= MOVMAX; i++) {
  369.         if (obloc[i] == ZENLAR + 2000) {
  370.         if (fimage != 0 && fimage != i)
  371.             filmst = 1;
  372.         qq = i;
  373.         objen += 1;
  374.         }
  375.     }
  376.     if (objen > 1)
  377.         filmst = 1;
  378.     if (objen == 0)
  379.         filmtm += 10;
  380.     if (objen >= 1) {
  381.         filmtm += 1;
  382.         fimage = qq;
  383.     }
  384.     } else if (obloc[ZBEAD] == obloc[ZCASSE] || (obloc[ZBEAD] != ZSINK
  385.                     + 2000 && bplce != 0 && cplce != 0))
  386.     filmtm += 1000;
  387.     else;
  388.     if (filmtm > 3000)
  389.     filmtm = 3000;
  390.     /*
  391.      * dispersing of the cloud from the seed we are using obimpr(zseed) as a
  392.      * clock; this is ok since it no longer exists (  o.e. obloc(zseed)=0 )
  393.      * despite this being stupid  
  394.      */
  395.  
  396.     if (obloc[ZSEED] == 0 && obimpr[ZSEED] > 0) {
  397.     if ((loc == 99 || loc == 131) && obimpr[ZSEED] == 1)
  398.         speak(406);
  399.     obimpr[ZSEED] -= 1;
  400.     }
  401.     if (screef > 0)
  402.     screef -= 1;
  403.     /* the chase is on!!!!    */
  404.  
  405.     if (chaset != 0) {
  406.     if (adverb == QUICKL)
  407.         chaser += 1;
  408.     if (chaset <= 8) {
  409.         if (xloc == loc || loc == oldlc2 || loc == 174 || loc == 166) {
  410.         if (chaset != 1) {
  411.             speak(557);
  412.             vdead();
  413.         } else
  414.             speak(554);
  415.         } else if (chaset >= 5 && chaser < 3)
  416.         speak(556);
  417.         else
  418.         speak(555);
  419.     } else if (chaset == 9) {
  420.         if (chaser >= 3) {
  421.         speak(558);
  422.         guardl = loc;
  423.         } else {
  424.         speak(557);
  425.         vdead();
  426.         }
  427.     } else if ((chaset > 9 && chaset < 18) && loc == guardl) {
  428.         speak(563);
  429.         vdead();
  430.     } else if (loc < 176 && chaset == 18) {
  431.         if (!(loc == 175 && (obimpr[BDOOR] & 2) != 0)) {
  432.         speak(560);
  433.         vdead();
  434.         }
  435.     }
  436.     chaset += 1;
  437.     if (chaset == 19)
  438.         chaset = 0;
  439.     }
  440. }
  441.