home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 7 Games / 07-Games.zip / MVTREK.ZIP / SUB1.C < prev    next >
Text File  |  1990-06-04  |  17KB  |  788 lines

  1. /* sub1.c -- subroutines for visual star trek */
  2.  
  3. #include "vtrek.h"
  4.  
  5. #ifdef HI_TECH_C
  6. #define atan2 atan
  7. #endif
  8.  
  9. /* print short help information */
  10. help()
  11. {
  12.     if (rolines > 5)
  13.         readout(CLEAR, NULL);
  14.     readout(ADDLINE, "Directions = Q,W,E,A,D,Z,X,C");
  15.     readout(ADDLINE, "H = Hyper-space      S = Short range scan");
  16.     readout(ADDLINE, "L = Long range scan  P = Fire phasers");
  17.     readout(ADDLINE, "T = Fire torpedo     U = Defense control");
  18.     readout(ADDLINE, "R = Redraw screen    F = Fix devices");
  19. }
  20.  
  21. /* get command character */
  22. getcmd()
  23. {
  24.     int ch;
  25.     char str[40];
  26.  
  27.         fflush(stdout);
  28.         sprintf(str, "Command, Captain %s ? ", captain);
  29.     prompt(str);
  30.         fflush(stdout);
  31.  
  32.         ch = getchar();
  33.         fflush(stdout);
  34.         fflush(stdin);
  35.  
  36.     return Toupper(ch);
  37. }
  38.  
  39. /* give option to see instructions */
  40. instructions()
  41. {
  42.     FILE *fp;
  43.     char line[80];
  44.     int n, ch;
  45.  
  46.         fflush(stdin);
  47.         fflush(stdout);
  48.         printf("Instructions <y/N>? ");
  49.         fflush(stdout);
  50.  
  51. /* Took out chready().  see original src! */
  52.  
  53.     if (fgets(line, 80, stdin) == (char *)NULL)
  54.         vexit(0);
  55.         fflush(stdin);
  56.         fflush(stdout);
  57.     ch = Toupper(line[0]);
  58.     if (ch == 'Y') {
  59.         if ((fp = fopen(VTREKINS, "r")) == (FILE *)NULL)
  60.         printf("Error: Missing instruction file\n");
  61.         else {
  62.         terminit();
  63.         for (;;) {
  64.             cls();
  65.             for (n = 0; n < 22; n++) {
  66.             if (fgets(line, 80, fp) == (char *)NULL)
  67.                 break;
  68.             printf("%s", line);
  69.                         fflush(stdout);
  70. #ifdef UNIX
  71.             putchar('\r');
  72. #endif
  73.             }
  74.             if (n < 22)
  75.             break;
  76.             printf("--More--");
  77.                     fflush(stdout);
  78.                     getchar();
  79.                     fflush(stdout);
  80.                     fflush(stdin);
  81.         }
  82.         fclose(fp);
  83.         termreset();
  84.         }
  85.     }
  86. }
  87.  
  88. /* get captain's name and ship's name */
  89. getnames()
  90. {
  91.     int tmp;
  92.         fflush(stdout);
  93.     printf("Your name captain ? ");
  94.         fflush(stdout);
  95.     if (fgets(captain, 11, stdin) == (char *)NULL)
  96.         vexit(1);
  97.         fflush(stdout);
  98.         fflush(stdin);
  99.     if (captain[tmp = strlen(captain) - 1] == '\n')
  100.         captain[tmp] = '\0';
  101.     else
  102.         while (getchar() != '\n');
  103.     if (*captain == '\0')
  104.         strcpy(captain, "Kirk");
  105.  
  106.         fflush(stdout);
  107.     printf("Your ship's name captain ? ");
  108.         fflush(stdout);
  109.     if (fgets(shipname, 11, stdin) == (char *)NULL)
  110.         vexit(1);
  111.         fflush(stdout);
  112.         fflush(stdin);
  113.     if (shipname[tmp = strlen(shipname) - 1] == '\n')
  114.         shipname[tmp] = '\0';
  115.     else
  116.         while (getchar() != '\n');
  117.     if (*shipname == '\0')
  118.         strcpy(shipname, "Enterprise");
  119. }
  120.  
  121. /* get skill level */
  122. getskill()
  123. {
  124.     char level[10];
  125.  
  126.         fflush(stdout);
  127.     printf("Skill level (0-5, 0=easy, 5=hard) ? ");
  128.         fflush(stdout);
  129.     if (fgets(level, 10, stdin) == (char *)NULL)
  130.         vexit(1);
  131.         fflush(stdin);
  132.         fflush(stdout);
  133.     if (isdigit(level[0]))
  134.         skill = level[0] - '0';
  135.     else
  136.         skill = 3;
  137. }
  138.  
  139. /* initialize galaxy */
  140. initgal()
  141. {
  142.     int i, j, k, r, n;
  143.  
  144.     numkling = 0;
  145.  
  146.     for (i = 0; i < 8; i++) {
  147.         for (j = 0; j < 8; j++) {
  148.         if ((r = rnd(100)) < 10)
  149.             k = 3;
  150.         else if (r < 20)
  151.             k = 2;
  152.         else if (r < 30)
  153.             k = 1;
  154.         else
  155.             k = 0;
  156.         numkling += k;
  157.         galaxy[i][j].nkling = k;
  158.         galaxy[i][j].nstar = rnd(8) + 1;
  159.         galaxy[i][j].nbase = 0;
  160.         galaxy[i][j].known = 0;
  161.         }
  162.     }
  163.  
  164.     numbases = rnd(3) + 2;
  165.  
  166.     for (n = 0; n < numbases; n++) {
  167.         for (;;) {
  168.         if (galaxy[i = rnd(7)][j = rnd(7)].nbase == 0) {
  169.             galaxy[i][j].nbase = 1;
  170.             break;
  171.         }
  172.         }
  173.     }
  174. }
  175.  
  176. /* initialize variables */
  177. initvars()
  178. {
  179.     int i;
  180.  
  181.     getnames();
  182.     getskill();
  183.     initgal();
  184.  
  185.     numkmove = skill;
  186.     begkling = numkling;
  187.     xquad = rnd(7);
  188.     yquad = rnd(7);
  189.     old_xsect = (xsect = rnd(7));
  190.     old_ysect = (ysect = rnd(7));
  191.     shields = 0;
  192.     energy = 3000;
  193.     stardate = 2000.0;
  194.     begdate = stardate;
  195.     lastdate = stardate + (float)numkling;
  196.     torps = 10;
  197.     playership[1] = *shipname;
  198.     condition = YELLOW;
  199.  
  200.     for (i = 0; i < 8; i++)
  201.         damage[i] = 100;
  202.     
  203.     old_xquad = -1;
  204.     old_yquad = -1;
  205.     setpos();
  206. }
  207.  
  208. /* set new position -- check for outside galaxy, set up new quadrant */
  209. setpos()
  210. {
  211.     int dam = 0, i, j, n, status = 0;
  212.     static int notfirstcall = 0;
  213.  
  214.     if (xsect > 7) {
  215.         xsect = 0;
  216.         xquad++;
  217.     }
  218.     else if (xsect < 0) {
  219.         xsect = 7;
  220.         xquad--;
  221.     }
  222.  
  223.     if (ysect > 7) {
  224.         ysect = 0;
  225.         yquad++;
  226.     }
  227.     else if (ysect < 0) {
  228.         ysect = 7;
  229.         yquad--;
  230.     }
  231.  
  232.     if (xquad > 7) {
  233.         dam = 1;
  234.         xquad = 7;
  235.         xsect = 7;
  236.     }
  237.     else if (xquad < 0) {
  238.         dam = 1;
  239.         xquad = 0;
  240.         xsect = 0;
  241.     }
  242.  
  243.     if (yquad > 7) {
  244.         dam = 1;
  245.         yquad = 7;
  246.         ysect = 7;
  247.     }
  248.     else if (yquad < 0) {
  249.         dam = 1;
  250.         yquad = 0;
  251.         ysect = 0;
  252.     }
  253.  
  254.     if (dam) {
  255.         readout(ADDLINE, "You encounter a force field.");
  256.         shields -= rnd(20) + 90;
  257.         plt_stat(ELEMENT, SHIELDS);
  258.         status = DAMAGE;
  259.         if (shields < 0)
  260.         die();
  261.     }
  262.  
  263.     if (xquad != old_xquad || yquad != old_yquad) {
  264.         galaxy[xquad][yquad].known = 1;
  265.         if (notfirstcall) {
  266.         plt_gal(ELEMENT, old_xquad, old_yquad);
  267.             plt_gal(ELEMENT, xquad, yquad);
  268.         }
  269.  
  270.         for (i = 0; i < 8; i++)
  271.         for (j = 0; j < 8; j++)
  272.             quadrant[i][j] = EMPTY;
  273.  
  274.         quadrant[xsect][ysect] = PLAYER;
  275.  
  276.         for (n = 0; n < galaxy[xquad][yquad].nkling; n++) {
  277.         for (;;) {
  278.             if (quadrant[i = rnd(7)][j = rnd(7)] == EMPTY) {
  279.             quadrant[i][j] = KLINGON;
  280.             break;
  281.             }
  282.         }
  283.         klingon[n].xs = i;
  284.         klingon[n].ys = j;
  285.         klingon[n].sh = 200;
  286.         }
  287.  
  288.         for (; n < 3; n++)
  289.         klingon[n].xs = klingon[n].ys = klingon[n].sh = -1;
  290.  
  291.         for (n = 0; n < galaxy[xquad][yquad].nbase; n++)
  292.         for (;;) {
  293.             if (quadrant[i = rnd(7)][j = rnd(7)] == EMPTY) {
  294.             quadrant[i][j] = STARBASE;
  295.             base_xsect = i;
  296.             base_ysect = j;
  297.             break;
  298.             }
  299.         }
  300.  
  301.         for (n = 0; n < galaxy[xquad][yquad].nstar; n++)
  302.         for (;;) {
  303.             if (quadrant[i = rnd(7)][j = rnd(7)] == EMPTY) {
  304.             quadrant[i][j] = STAR;
  305.             break;
  306.             }
  307.         }
  308.  
  309.         old_xquad = xquad;
  310.         old_yquad = yquad;
  311.         if (notfirstcall) {
  312.             plt_srs(INFO);
  313.             plt_stat(ELEMENT, CONDITION);
  314.             plt_stat(ELEMENT, QUADRANT);
  315.             plt_gal(ELEMENT, xquad, yquad);
  316.         }
  317.     }
  318.     else {
  319.         switch (quadrant[xsect][ysect]) {
  320.  
  321.         case KLINGON:
  322.         dam = rnd(20) + 90;
  323.         if (damkling(xsect, ysect, dam) != DEAD) {
  324.             xsect = old_xsect;
  325.             ysect = old_ysect;
  326.         }
  327.         dam >>= 1;
  328.         if ((shields -= dam) < 0)
  329.             die();
  330.         fixdev(REL, RND, -dam);
  331.         plt_stat(ELEMENT, SHIELDS);
  332.         break;
  333.  
  334.         case STAR:
  335.         readout(ADDLINE, "There's a star in the way, Dunce!");
  336.         if (damage[SRS] > 0)
  337.             strcpy(captain, "Dunce");
  338.         xsect = old_xsect;
  339.         ysect = old_ysect;
  340.         break;
  341.  
  342.         case STARBASE:
  343.         xsect = old_xsect;
  344.         ysect = old_ysect;
  345.         readout(ADDLINE, "There's a star base in the way!");
  346.         break;
  347.         }
  348.  
  349.         status = quadrant[xsect][ysect];
  350.         quadrant[old_xsect][old_ysect] = EMPTY;
  351.         quadrant[xsect][ysect] = PLAYER;
  352.         plt_srs(ELEMENT, old_xsect, old_ysect);
  353.         plt_srs(ELEMENT, xsect, ysect);
  354.     }
  355.     old_xsect = xsect;
  356.     old_ysect = ysect;
  357.     if (notfirstcall)
  358.         plt_stat(ELEMENT, SECTOR);
  359.     notfirstcall = 1;
  360.  
  361.     return status;
  362. }
  363.  
  364. /* "So this is it.  We're going to die." -- Arthur Dent */
  365. die()
  366. {
  367.     plt_stat(ELEMENT, SHIELDS);
  368.     prompt("(Press RETURN)");
  369.         fflush(stdout);
  370.         fflush(stdin);
  371.         getchar();
  372.         fflush(stdout);
  373.     cls();
  374.         fflush(stdout);
  375.     score(0);
  376.     moveyx(15, 21);
  377.     printf("Your ship the %s has been destroyed.", shipname);
  378.         fflush(stdout);
  379.     moveyx(16, 21);
  380.     printf("The Federation will be conquered.\n\n\n\r");
  381.         fflush(stdout);
  382.     vexit(0);
  383. }
  384.  
  385. win()
  386. {
  387.     readout(ADDLINE, "Congratulations!");
  388.         fflush(stdout);
  389.     prompt("(Press RETURN)");
  390.         fflush(stdout);
  391.         getchar();
  392.         fflush(stdout);
  393.     cls();
  394.         fflush(stdout);
  395.     score(1);
  396.     moveyx(20,1);
  397.         fflush(stdout);
  398.     printf("[Press Return]\n");
  399.         fflush(stdout);
  400.         getchar();
  401.         fflush(stdout);
  402.     cls();
  403.         fflush(stdout);
  404.     moveyx(11, 16);
  405.         fflush(stdout);
  406.     printf("The last of the Klingon battle cruisers have been\n");
  407.         fflush(stdout);
  408.     printf("%15sdestroyed.  You alone have saved the Federation.  You\n", "");
  409.         fflush(stdout);
  410.     printf("%15sare promoted to Admiral %s !!!\n\n\n\r", "", captain);
  411.         fflush(stdout);
  412.     vexit(0);
  413. }
  414.  
  415. /* random (?) number generator */
  416. rnd(max)
  417. int max;
  418. {
  419. #ifdef AZTEC
  420.     static long iy = 0x86A186A1;
  421.  
  422.     iy *= 125;
  423.     iy &= 0x7FFFFFFF;
  424.     iy %= 0xAAAAAAAd;
  425.  
  426.     return (int)((iy >> 8) % max);
  427. #else
  428.     return (int)(rand() % max);
  429. #endif
  430. }
  431.  
  432. #ifdef UNIX
  433. /* randomize */
  434. randomize()
  435. {
  436.     srand(time(0));
  437. }
  438. #endif
  439.  
  440. /* impulse drive -- move one sector */
  441. impulse(dir)
  442. int dir;
  443. {
  444.     int dx, dy, status;
  445.  
  446.     if (energy <= 0) {
  447.         readout(ADDLINE, "Insufficient energy for command.");
  448.         return ERROR;
  449.     }
  450.  
  451.     if (checkdir(dir, &dx, &dy) != ERROR) {
  452.         xsect += dx;
  453.         ysect += dy;
  454.     }
  455.  
  456.     energy--;
  457.     status = setpos();
  458.     plt_stat(ELEMENT, ENERGY);
  459.  
  460.     return status;
  461. }
  462.  
  463. /* defense -- set shield level */
  464. defense()
  465. {
  466.     if (damage[DEFENSE] <= 0)
  467.         readout(ADDLINE, "Defense control is damaged.");
  468.     else {
  469.         energy += shields;
  470.         for (;;) {    
  471.             prompt("Shield level ? ");
  472.             if ((shields = getnumb()) >= 0 && shields <= energy) {
  473.                 energy -= shields;
  474.             break;
  475.         }
  476.         }
  477.         if (shields > 0) {
  478.         playership[0] = '(';
  479.         playership[2] = ')';
  480.         }
  481.         else {
  482.         playership[0] = ' ';
  483.         playership[2] = ' ';
  484.         }
  485.         plt_srs(ELEMENT, xsect, ysect);
  486.         plt_stat(ELEMENT, SHIELDS);
  487.         plt_stat(ELEMENT, ENERGY);
  488.     }
  489. }
  490.  
  491. /* get a number */
  492. getnumb()
  493. {
  494.     int num = 0, ch;
  495.  
  496.         fflush(stdout);
  497.         while ((ch = getchar()) != '\r') {
  498.             fflush(stdout);
  499.             putchar(ch);
  500.             fflush(stdout);
  501.         if (isdigit(ch))
  502.         num = num * 10 + ch - '0';
  503.         else if (ch == '\b') {
  504.         num = num / 10;
  505.                 fflush(stdout);
  506.                 putchar(' ');
  507.                 fflush(stdout);
  508.                 putchar('\b');
  509.                 fflush(stdout);
  510.         }
  511.         else
  512.         break;
  513.     }
  514.  
  515.     return num;
  516. }
  517.  
  518. /* damage a klingon */
  519. damkling(xs, ys, dam)
  520. int xs, ys, dam;
  521. {
  522.     char str[40];
  523.     int k;
  524.  
  525.     if ((k = findkling(xs, ys)) == ERROR)
  526.         readout(ADDLINE, "damkling: error");
  527.     else {
  528.         if (dam != AUTOKILL) {
  529.             sprintf(str, "You did %d to the Klingon.", dam);
  530.             readout(ADDLINE, str);
  531.                 fflush(stdout);
  532.         }
  533.  
  534.         if ((klingon[k].sh -= dam) < 0) {
  535.         readout(ADDLINE, "Klingon destroyed.");
  536.                 fflush(stdout);
  537.         klingon[k].xs = klingon[k].ys = -1;
  538.         quadrant[xs][ys] = EMPTY;
  539.         plt_srs(ELEMENT, xs, ys);
  540.         numkling--;
  541.         plt_num(INFO);
  542.         galaxy[xquad][yquad].nkling--;
  543.         plt_gal(ELEMENT, xquad, yquad);
  544.  
  545.         return DEAD;
  546.         }
  547.     }
  548.  
  549.     return ALIVE;
  550. }
  551.  
  552. /* fix/damage a device */
  553. fixdev(type, dev, value)
  554. int type;    /* ABSolution fix or RELative fix */
  555. int dev;    /* device (if RND then pick a damaged device) */
  556. int value;    /* new device value for ABS, amount to add for REL */
  557. {
  558.     int i, old_dam;
  559.  
  560.     if (dev == RND) {
  561.         dev = rnd(8);
  562.         if (value > 0 && damage[dev] >= 100) {
  563.         for (i = 0; i < 8; i++) {
  564.             if (++dev > 7)
  565.             dev = 0;
  566.             if (damage[dev] < 100)
  567.             break;
  568.         }
  569.         }
  570.     }
  571.  
  572.     old_dam = damage[dev];
  573.  
  574.     if (type == ABS)
  575.         damage[dev] = value;
  576.     else
  577.         damage[dev] += value;
  578.  
  579.     if (damage[dev] > 100)
  580.         damage[dev] = 100;
  581.  
  582.     plt_dam(ELEMENT, dev);
  583.  
  584.     /* see if device changed from fixed <==> broken */
  585.     if ((old_dam <= 0 && damage[dev] > 0) || (old_dam > 0 && damage[dev] <= 0)) {
  586.         switch (dev) {
  587.         case SRS :
  588.             plt_srs(INFO);
  589.             break;
  590.         case DAMAGE :
  591.             plt_dam(INFO);
  592.             break;
  593.         case COMPUTER :
  594.             plt_gal(INFO);
  595.             break;
  596.         }
  597.     }
  598. }
  599.  
  600. /* print a prompt in the upper left hand corner */
  601. prompt(str)
  602. char *str;
  603. {
  604.     int i;
  605.  
  606.     moveyx(1, 1);
  607.         fflush(stdout);
  608.     for (i = 0; i < 26; i++)
  609.             putchar(' ');
  610.     moveyx(1, 1);
  611.         fflush(stdout);
  612.     printf("%-.26s", str);
  613.         fflush(stdout);
  614. }
  615.  
  616. /* check a direction for validity and return delta-x and delta-y */
  617. checkdir(dir, dx, dy)
  618. int dir, *dx, *dy;
  619. {
  620.     static struct {
  621.         int d, x, y;
  622.     } dirs[8] = {
  623.         {'Q', -1, -1}, {'W', 0, -1}, {'E', 1, -1}, {'D', 1, 0},
  624.         {'C', 1, 1}, {'X', 0, 1}, {'Z', -1, 1}, {'A', -1, 0}
  625.     };
  626.     int i;
  627.  
  628.     for (i = 0; i < 8; i++)
  629.         if (dirs[i].d == dir) {
  630.         *dx = dirs[i].x;
  631.         *dy = dirs[i].y;
  632.         return 0;
  633.         }
  634.  
  635.     return ERROR;
  636. }
  637.  
  638. /* hyperspace drive */
  639. hyperspace()
  640. {
  641.     int dir, dx, dy, w, tmp, savex, savey;
  642.  
  643.     if (damage[WARP] <= 0)
  644.         readout(ADDLINE, "Warp engines are damaged.");
  645.     else {
  646.         prompt("Direction ? ");
  647.             fflush(stdout);
  648.             if (islower(dir = getchar()))
  649.         dir = toupper(dir);
  650.             fflush(stdin);
  651.             fflush(stdout);
  652.         if (checkdir(dir, &dx, &dy) == ERROR) {
  653.         readout(ADDLINE, "Illegal direction.");
  654.         return;
  655.         }
  656.  
  657.             fflush(stdout);
  658.         prompt("Warp ? ");
  659.             fflush(stdout);
  660.             putchar(w = getchar());
  661.             fflush(stdin);
  662.             fflush(stdout);
  663.         if (isdigit(w)) {
  664.         w -= '0';
  665.             if (w <= 0)
  666.             return;
  667.             savex = xsect;
  668.             savey = ysect;
  669.             while ((tmp = xsect + dx) >= 0 && tmp <= 7 && (tmp = ysect + dy) >= 0 && tmp <= 7) {
  670.             if (impulse(dir))
  671.                 return;
  672.             }
  673.             if (energy < 20 * w)
  674.             readout(ADDLINE, "Insufficient energy for command.");
  675.             else {
  676.                 xquad += w * dx;
  677.                 yquad += w * dy;
  678.                 energy -= 20 * w;
  679.             stardate += (double)(w) / 5.0;
  680.                 xsect = savex;
  681.                 ysect = savey;
  682.                 setpos();
  683.                 plt_stat(ELEMENT, ENERGY);
  684.             }
  685.         }
  686.             else if (w == '.' && isdigit(w = getchar())) {
  687.                 fflush(stdout);
  688.                 fflush(stdin);
  689.                 putchar(w);
  690.         w -= '0';
  691.         stardate += (double)(w) / 50.0;
  692.         for (; w > 0; w--)
  693.             if (impulse(dir))
  694.             break;
  695.         }
  696.         else
  697.         readout(ADDLINE, "Illegal warp factor.");
  698.     }
  699. }
  700.  
  701. /* long range scan */
  702. lrs()
  703. {
  704.     int x, y;
  705.     char str[20];
  706.  
  707.     if (damage[LRS] <= 0)
  708.         readout(ADDLINE, "Long range sensors are damaged.");
  709.     else {
  710.         if (rolines > 3)
  711.         readout(CLEAR, NULL);
  712.  
  713.         for (y = yquad - 1; y <= yquad + 1; y++) {
  714.         readout(ADDLINE, "+---+---+---+");
  715.         strcpy(str, "|");
  716.         for (x = xquad - 1; x <= xquad + 1; x++) {
  717.             if (x < 0 || x > 7 || y < 0 || y > 7)
  718.             strcat(str, "XXX");
  719.             else {
  720.             if (damage[COMPUTER] > 0)
  721.                 galaxy[x][y].known = 1;
  722.             sprintf(str + strlen(str), "%d%d%d", galaxy[x][y].nkling,
  723.             galaxy[x][y].nbase, galaxy[x][y].nstar);
  724.             plt_gal(ELEMENT, x, y);
  725.             }
  726.             strcat(str, "|");
  727.         }
  728.         str[13] = '\0';
  729.         readout(ADDLINE, str);
  730.         }
  731.  
  732.         readout(ADDLINE, "+---+---+---+");
  733.         plt_gal(ELEMENT, xquad, yquad);
  734.     }
  735. }
  736.  
  737. /* short range scan */
  738. srs()
  739. {
  740.     int k, dx, dy;
  741.     double dir, dist;
  742.     char str[40];
  743.  
  744.     if (damage[SRS] <= 0)
  745.         readout(ADDLINE, "Short range sensors are damaged.");
  746.     else {
  747.         if (rolines > 6)
  748.         readout(CLEAR, NULL);
  749.         readout(ADDLINE, "Sector  Direction  Distance");
  750.         for (k = 0; k < 3; k++) {
  751.         if (klingon[k].sh >= 0) {
  752.             if (damage[COMPUTER] <= 0)
  753.             sprintf(str, "[%d,%d]", klingon[k].xs+1, klingon[k].ys+1);
  754.             else {
  755.             dx = klingon[k].xs - xsect;
  756.             dy = klingon[k].ys - ysect;
  757.             dist = sqrt((double)(dx*dx) + (double)(dy*dy));
  758.             if (dx) {
  759.                 dir = atan2(-(double)dy, (double)dx) * 180.0 / PI;
  760.                 if (dir < 0.0)
  761.                 dir += 360.0;
  762.             }
  763.             else if (dy > 0)
  764.                 dir = 270.0;
  765.             else
  766.                 dir = 90.0;
  767.             sprintf(str, "[%d,%d]     %5.1f      %4.1f", klingon[k].xs+1,
  768.             klingon[k].ys+1, dir, dist);
  769.             }
  770.             readout(ADDLINE, str);
  771.         }
  772.         }
  773.     }
  774. }
  775.  
  776. findkling(x, y)
  777. int x, y;
  778. {
  779.     int i;
  780.  
  781.     for (i = 0; i < 3; i++)
  782.         if (x == klingon[i].xs && y == klingon[i].ys)
  783.         return i;
  784.  
  785.     return ERROR;
  786. }
  787. 
  788.