home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 7 Games / 07-Games.zip / MVTREK.ZIP / PLOT.C < prev    next >
C/C++ Source or Header  |  1990-06-13  |  8KB  |  337 lines

  1. /* plot.c -- plot routines for visual star trek */
  2.  
  3. #include "vtrek.h"
  4.  
  5. /* replot screen */
  6. replot()
  7. {
  8.     cls();
  9.     plt_stat(ALL);
  10.     plt_srs(ALL);
  11.     plt_dam(ALL);
  12.     plt_gal(ALL);
  13.     moveyx(12, 56);
  14.         fflush(stdout);
  15.     printf("READOUT");
  16.         fflush(stdout);
  17.     moveyx(13, 56);
  18.     printf("-------");
  19.         fflush(stdout);
  20.     plt_num(ALL);
  21. }
  22.  
  23. /* plot status (upper left) */
  24. plt_stat(op, item)
  25. int op, item;
  26. {
  27.     static char *text[9] = {
  28.         "      Status", "      ------", "Stardate     :",
  29.         "Condition    :", "Quadrant     :", "Sector       :",
  30.         "Energy       :", "Photon torps :", "Shields      :"
  31.     };
  32.     static char *ctext[4] = {
  33.         "Green", "Yellow", "Red", "Docked"
  34.     };
  35.     int i, high, low;
  36.  
  37.     if (op & TEXT)
  38.         for (i = 0; i < 9; i++) {
  39.         moveyx(i + 2, 1);
  40.                 fflush(stdout);
  41.         printf("%s", text[i]);
  42.                 fflush(stdout);
  43.         }
  44.  
  45.     if (op & (INFO | ELEMENT)) {
  46.         if (op & INFO) {
  47.         low = STARDATE;
  48.         high = SHIELDS;
  49.         }
  50.         else {
  51.         low = item;
  52.         high = item;
  53.         }
  54.  
  55.         for (i = low; i <= high; i++) {
  56.         switch (i) {
  57.         case STARDATE :
  58.             moveyx(4, 16);
  59.                     fflush(stdout);
  60.             printf("%-.1f", stardate);
  61.                     fflush(stdout);
  62.             break;
  63.         case CONDITION :
  64.             moveyx(5, 16);
  65.                     fflush(stdout);
  66.             printf("%-6s", ctext[condition]);
  67.                     fflush(stdout);
  68.             break;
  69.         case QUADRANT :
  70.             moveyx(6, 16);
  71.                     fflush(stdout);
  72.             printf("[%d,%d]", xquad + 1, yquad + 1);
  73.                     fflush(stdout);
  74.             break;
  75.         case SECTOR :
  76.             moveyx(7, 16);
  77.                     fflush(stdout);
  78.             printf("[%d,%d]", xsect + 1, ysect + 1);
  79.                     fflush(stdout);
  80.             break;
  81.         case ENERGY :
  82.             moveyx(8, 16);
  83.                     fflush(stdout);
  84.             printf("%-4d", energy);
  85.                     fflush(stdout);
  86.             break;
  87.         case TORPS :
  88.             moveyx(9, 16);
  89.                     fflush(stdout);
  90.             printf("%-2d", torps);
  91.                     fflush(stdout);
  92.             break;
  93.         case SHIELDS :
  94.             moveyx(10, 16);
  95.                     fflush(stdout);
  96.             printf("%-4d", shields);
  97.                     fflush(stdout);
  98.             break;
  99.         }
  100.         }
  101.     }
  102. }
  103.  
  104. /* plot short range scan */
  105. plt_srs(op, xs, ys)
  106. int op, xs, ys;
  107. {
  108.     static char *htext = "-1--2--3--4--5--6--7--8-";
  109.     static char *stext[6] = {
  110.         "   ", "<K>", "<S>", " * ", "???", " + "
  111.     };
  112.     int i, j;
  113.  
  114.     if (op & TEXT) {
  115.         moveyx(1, 28);
  116.             fflush(stdout);
  117.         printf("%s", htext);
  118.             fflush(stdout);
  119.         for (i = 1; i < 9; i++) {
  120.         moveyx(i + 1, 27);
  121.         printf("%d", i);
  122.                 fflush(stdout);
  123.         moveyx(i + 1, 52);
  124.         printf("%d", i);
  125.                 fflush(stdout);
  126.         }
  127.         moveyx(10, 28);
  128.         printf("%s", htext);
  129.             fflush(stdout);
  130.     }
  131.  
  132.     strcpy(stext[PLAYER], playership);
  133.  
  134.     if (op & INFO) {
  135.         for (i = 0; i < 8; i++) {
  136.         moveyx(i + 2, 28);
  137.                 fflush(stdout);
  138.         for (j = 0; j < 8; j++)
  139.             printf("%s", stext[(damage[SRS] <= 0) ? EMPTY : quadrant[j][i]]);
  140.         }
  141.     }
  142.     else if (op & ELEMENT) {
  143.         moveyx(ys + 2, 28 + 3 * xs);
  144.             fflush(stdout);
  145.         printf("%s", stext[(damage[SRS] <= 0) ? EMPTY : quadrant[xs][ys]]);
  146.             fflush(stdout);
  147.     }
  148. }
  149.  
  150. /* plot damage info */
  151. plt_dam(op, item)
  152. int op, item;
  153. {
  154.     static char *text[10] = {
  155.         "    Damage Report", "    -------------",
  156.         "Warp engines    :", "S.R. sensors    :", "L.R. sensors    :",
  157.         "Phaser control  :", "Damage control  :", "Defense control :",
  158.         "Computer        :", "Photon tubes    :"
  159.     };
  160.     int i;
  161.  
  162.         fflush(stdout);
  163.     if (op & TEXT)
  164.         for (i = 0; i < 10; i++) {
  165.         moveyx(i + 1, 56);
  166.         printf("%s", text[i]);
  167.         }
  168.  
  169.         fflush(stdout);
  170.     if (op & INFO)
  171.         for (i = 0; i < 8; i++) {
  172.         moveyx(i + 3, 74);
  173.         if (damage[DAMAGE] <= 0)
  174.             printf("    ");
  175.         else
  176.             printf("%4d", damage[i]);
  177.         }
  178.     else if (op & ELEMENT) {
  179.         moveyx(item + 3, 74);
  180.             fflush(stdout);
  181.         if (damage[DAMAGE] <= 0)
  182.         printf("    ");
  183.         else
  184.         printf("%4d", damage[item]);
  185.     }
  186. }
  187.  
  188. /* plot galaxy map */
  189. plt_gal(op, xq, yq)
  190. int op, xq, yq;
  191. {
  192.     static char *htext = "-1- -2- -3- -4- -5- -6- -7- -8-";
  193.     int i, j, fedquad;
  194.  
  195.         fflush(stdout);
  196.     if (op & TEXT) {
  197.         moveyx(13, 3);
  198.         printf("%s", htext);
  199.             fflush(stdout);
  200.         for (i = 1; i < 9; i++) {
  201.         moveyx(i + 13, 1);
  202.         printf("%d|", i);
  203.                 fflush(stdout);
  204.         for (j = 0; j < 7; j++) {
  205.                     moveyx(i + 13, 6 + (j << 2));
  206.                     fflush(stdout);
  207.                     putchar('|');
  208.                     fflush(stdout);
  209.         }
  210.         moveyx(i + 13, 34);
  211.         printf("|%d", i);
  212.                 fflush(stdout);
  213.         }
  214.         moveyx(22, 3);
  215.         printf("%s", htext);
  216.             fflush(stdout);
  217.     }
  218.  
  219.         fflush(stdout);
  220.     if (op & INFO) {
  221.         for (i = 0; i < 8; i++)
  222.         for (j = 0; j < 8; j++) {
  223.             moveyx(i + 14, 3 + (j << 2));
  224.             if (damage[COMPUTER] <= 0 || !galaxy[j][i].known)
  225.             printf("   ");
  226.             else {
  227.             if ( galaxy[j][i].nkling > 0 )
  228.                 printf("%01d",galaxy[j][i].nkling );
  229.             else
  230.                 printf("%s"," ");
  231.             if ( galaxy[j][i].nbase > 0 )
  232.                 printf("%s%01d", "B", galaxy[j][i].nstar);
  233.             else
  234.                 printf("%s%01d", " ", galaxy[j][i].nstar);
  235.             }
  236.         }
  237.         moveyx(yquad + 14, 2 + (xquad << 2));
  238.             fflush(stdout);
  239.         putch('[');
  240.             fflush(stdout);
  241.         moveyx(yquad + 14, 6 + (xquad << 2));
  242.         putch(']');
  243.             fflush(stdout);
  244.     }
  245.     else if (op & ELEMENT) {
  246.         moveyx(yq + 14, 2 + (xq << 2));
  247.         fedquad = (xq == xquad && yq == yquad);
  248.             fflush(stdout);
  249.         putch(fedquad ? '[' : '|');
  250.             fflush(stdout);
  251.         if (damage[COMPUTER] <= 0)
  252.         printf("   ");
  253.         else {
  254.         if ( galaxy[xq][yq].nkling > 0 )
  255.             printf("%01d",galaxy[xq][yq].nkling );
  256.         else
  257.             printf("%s"," ");
  258.         if ( galaxy[xq][yq].nbase > 0 )
  259.             printf("%s%01d", "B", galaxy[xq][yq].nstar);
  260.         else
  261.             printf("%s%01d", " ", galaxy[xq][yq].nstar);
  262.         }
  263.             fflush(stdout);
  264.         putch(fedquad ? ']' : '|');
  265.             fflush(stdout);
  266.     }
  267. }
  268.  
  269. /* plot number of star bases & klingons */
  270. plt_num(op)
  271. int op;
  272. {
  273.     float kf;
  274.  
  275.     if (op & TEXT) {
  276.         moveyx(23, 3);
  277.             fflush(stdout);
  278.         printf("Base stars = ");
  279.             fflush(stdout);
  280.         moveyx(23, 19);
  281.         printf("Klingons = ");
  282.             fflush(stdout);
  283.         moveyx(24, 10);
  284.         printf("Kill Factor = ");
  285.             fflush(stdout);
  286.     }
  287.  
  288.     if (op & INFO) {
  289.         moveyx(23, 15);
  290.         printf(" %d", numbases);
  291.             fflush(stdout);
  292.         moveyx(23, 30);
  293.         printf(" %d/%d  ", numkling, begkling);
  294.             fflush(stdout);
  295.         moveyx(24, 24);
  296.         if (begdate != stardate)
  297.         kf = (begkling - numkling) / (stardate - begdate);
  298.         else
  299.         kf = 0.0;
  300.         printf("%5.3f  ", kf);
  301.             fflush(stdout);
  302.     }
  303. }
  304.  
  305. /* change readout */
  306. readout(op, str)
  307. int op;
  308. char *str;
  309. {
  310.     int i;
  311.  
  312.     switch (op) {
  313.  
  314.     case CLEAR :        /* clear readout */
  315.  
  316.             fflush(stdout);
  317.         for (i = 14; i <= 13 + rolines; i++) {
  318.         moveyx(i, 38);
  319.         ceol();
  320.         }
  321.  
  322.             fflush(stdout);
  323.         rolines = 0;
  324.         break;
  325.  
  326.     case ADDLINE :        /* add line to readout */
  327.             fflush(stdout);
  328.         if (rolines >= 10)
  329.         readout(CLEAR, NULL);
  330.         moveyx(14 + rolines, 38);
  331.         printf("%-.44s", str);
  332.             fflush(stdout);
  333.         rolines++;
  334.         break;
  335.     }
  336. }
  337.