#include <stdio.h>
#include <strings.h>
#include <math.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include "c_defs.h"
#include "c_structs.h"
#include "c_externs.h"
  
/*
 * cbzone_graphics.c
 *  -- Todd W Mummert, December 1990, CMU
 *
 * This file is based on the Fortran source by
 * Justin S Revenaugh.  I've made each routine handle only
 * a single object, besides scanner() which handles multiple
 * objects.  Also, all drawing information about an object is
 * kept within the object's structure, not here in statics.
 */

void message(number, bell)
     int number;
     logical bell;
{
  static int xpt = 70;
  static int ypt[] = {507, 567, 627};
  static char* messages[] = {"ENEMY TANK IN FIRING ARC",
                               "MOVEMENT BLOCKED BY OBJECT",
                               "SALVO FIRED BY ENEMY TANK"};
  int ind;
  char text[41];
  
  ind = abs(number) - 1;
  if (number < 0) 
    sprintf(text,"%-40s"," ");
  else
    sprintf(text,"%-40s",messages[ind]);

  gprsetclippingactive(FALSE);
  printstring(xpt, ypt[ind], text, 40);
  gprsetclippingactive(TRUE);
  if (bell) 
    tonetime();
}

static int font1;
static int font2;
static int font3;
int icol[16];
static logical incolor;

void screeninit()
{
  static int value[] = {0, 16777215, 65280, 57600, 51200, 44800, 38400,
                          32000, 16777000, 14803200, 13158400, 11513600,
                          9868800, 8224000, 9868950, 16711700};
  int config, i;
  char answer[80];

  icol[0] = 0;
  for (i=1; i<16; i++)
    icol[i] = 1;
  incolor = FALSE;
  gprinqconfig(&config);
  /* original comment:  next line is almost certainly wrong. */
  if (config >= 2 && config < 100) { 
    incolor = TRUE;
    printf("Do you want fading colors? (y/n):");
    gets(answer);
    if (*answer == 'n' || *answer == 'N') { 
      for (i=3; i<8; i++)
        value[i] = value[2];
      for (i=9; i<14; i++)
        value[i] = value[8];
    } 
  }
  if (incolor) {
    gprsetcolormap();                   /* this section currently  */
    for (i=0; i<16; i++)                /* doesn't work */
      icol[i] = value[i];
  }
  gprloadfontfile("f5x9", &font1);
  gprloadfontfile("i.12", &font2);
  gprloadfontfile("f7x13", &font3);

  staticscreen();
}

void staticscreen()
{
  int window[2][2];
  int pt[2], radius;
  char text[30];
  static short line[] = {58, 66, 66, 58, 56, 438, 68, 438, 938, 56,
                           938, 68, 942, 442, 934, 434, 56, 472, 68, 472,
                           934, 468, 942, 476, 58, 644, 66, 652, 932, 648,
                           944, 648};
  static short scan[] = {500, 495, 500, 500, 500, 625, 500, 620, 435, 560,
                           440, 560, 565, 560, 560, 560};
  static short scrn[] = {75, 64, 925, 64, 936, 75, 936, 425, 925, 436,
                           75, 436, 64, 425, 64, 75, 75, 64};
  static short tank[] = {974, 47, 976, 43, 960, 43, 960, 42, 978, 42,
                           980, 40, 988, 40, 990, 45, 994, 44, 990, 55,
                           965, 55, 960, 49, 994, 44};
  extern void flushandsync();

  gprsetclippingactive(FALSE);
  gprsettextvalue(icol[1]);
  gprsettextbackgroundvalue(icol[0]);
  gprsetfillvalue(icol[1]);
  gprsetdrawvalue(icol[1]);
  radius = 4;
  pt[0] = 970;
  pt[1] = 70;
  gprcircle(pt, radius);
  radius = 5;
  gprcircle(pt, radius);
  radius = 4;
  pt[0] = 970;
  pt[1] = 100;
  gprcircle(pt, radius);
  radius = 5;
  gprcircle(pt, radius);
  fillrectangle(969, 60, 3, 10);
  fillrectangle(969, 100, 3, 10);
  pt[0] = 980;
  pt[1] = 20;
  radius = 10;
  gprcirclefilled(pt, radius);
  gprsetfillvalue(0);
  polyline(tank, 13);
  drawrectangle(50, 50, 900, 400);
  drawrectangle(53, 53, 894, 394);
  drawrectangle(50, 460, 900, 200);
  drawrectangle(53, 463, 894, 194);
  polyline(scrn, 9);
  pt[0] = 62;
  pt[1] = 62;
  radius = 6;
  gprcircle(pt, radius);
  pt[0] = 938;
  gprcircle(pt, radius);
  pt[1] = 438;
  gprcircle(pt, radius);
  pt[0] = 62;
  gprcircle(pt, radius);
  pt[0] = 62;
  pt[1] = 472;
  gprcircle(pt, radius);
  pt[0] = 938;
  gprcircle(pt, radius);
  pt[1] = 648;
  gprcircle(pt, radius);
  pt[0] = 62;
  gprcircle(pt, radius);
  multiline(line, 8);
  pt[0] = 500;
  pt[1] = 560;
  radius = 65;
  gprcircle(pt, radius);
  radius = 64;
  gprcircle(pt, radius);
  pt[0] = 855;
  pt[1] = 560;
  radius = 65;
  gprcircle(pt, radius);
  radius = 64;
  gprcircle(pt, radius);
  multiline(scan, 4);
  drawrectangle(590, 570, 55, 30);
  drawrectangle(655, 570, 55, 30);
  drawrectangle(590, 520, 120, 30);
  gprsettextfont(font2);
  strcpy(text, "BATTLE ZONE V.Ic");
  printstring(50, 45, text, 16);
  strcpy(text, "F");
  gprsettextvalue(icol[15]);
  printstring(850, 503, text, 1);
  strcpy(text, "B");
  printstring(850, 630, text, 1);
  strcpy(text, "R");
  printstring(913, 570, text, 1);
  strcpy(text, "L");
  printstring(785, 570, text, 1);
  gprsettextfont(font1);
  gprsettextvalue(icol[1]);
  strcpy(text, "Missile");
  printstring(595, 590, text, 7);
  strcpy(text, "Lander");
  printstring(664, 590, text, 6);
  strcpy(text, "H");
  printstring(920, 608, text, 1);
  strcpy(text, "L");
  printstring(920, 642, text, 1);
  window[0][0] = 70;
  window[0][1] = 75;
  window[1][0] = 860;
  window[1][1] = 350;
  gprsetclipwindow(window);
  gprsettextfont(font3);
  pt[0] = 500;
  pt[1] = 400;
  gprsetcursorposition(pt);
  gprsetclippingactive(TRUE);
}

void updatedisplay (missile, lander, score, numleft, sens, reset)
     logical missile, lander, sens, reset;
     int score, numleft;
{
  char text[11];
  static logical flasher[] = {FALSE, FALSE};
  static int currentnumleft = 0;
  static int currentscore = -1;
  static int dest1[] = {590, 570};
  static int dest2[] = {655, 570};
  static int bswitch[] = {916, 610};
  static int wind1[][2] = {590, 570, 55, 30};
  static int wind2[][2] = {655, 570, 55, 30};
  static int wind3[][2] = {960, 40, 35, 16};
  static int wind4[][2] = {964, 59, 12, 22};
  static int wind5[][2] = {964, 89, 12, 22};
  static int origin[][2] = {733, 493, 733, 533, 733, 573, 733, 613};
  static logical currentsens = TRUE;

  gprsetclippingactive(FALSE);
  if (reset) {
    flasher[0] = flasher[1] = FALSE;
    currentsens = TRUE;
  }
  
  if ((flasher[0] && !missile) ||
      (!flasher[0] && missile)) {
    flasher[0] = missile;
    gprsetrasterop(10);
    gprbitblt(wind1, dest1);
    gprsetrasterop(3);
  }
  if ((flasher[1] && !lander) ||
      (!flasher[1] && lander)) {
    flasher[1] = lander;
    gprsetrasterop(10);
    gprbitblt(wind2, dest2);
    gprsetrasterop(3);
  }
  if (score != currentscore) {
    currentscore = score;
    sprintf(text,"%10d",score);
    printstring(608, 542, text, strlen(text));
  }
  if (numleft < currentnumleft && numleft >= 0)
    while (numleft != currentnumleft) {
      gprsetrasterop(6);
      gprbitblt(wind3, origin[currentnumleft-1]);
      gprsetrasterop(3);
      currentnumleft--;
    }
  if (numleft > currentnumleft)
    while (numleft != currentnumleft && currentnumleft < 4) {
      gprbitblt(wind3, origin[currentnumleft]);
      currentnumleft++;
    }
  if (sens && !currentsens) {
    gprbitblt(wind4, bswitch);
    currentsens = sens;
  }
  else if (!sens && currentsens) {
    gprbitblt(wind5, bswitch);
    currentsens = sens;
  }
  gprsetclippingactive(TRUE);
}

void joystick (position, sens, pl)
     int position[];
     Genericp pl;
     logical sens;
{
  static int window[] = {970, 10, 21, 21};
  static float sscale[] = {0.05, 0.025};
  static float rscale[] = {0.00015, 0.000075};
  static int destorigin[] = {845, 550};
  static short stick[8] = {0};
  static logical first = TRUE;
  static logical draw = TRUE;
  int ind;
  float scrot, sctot, scale, xl, yl, tl, xoff, yoff;

  if (sens)
    ind = 0;
  else
    ind = 1;
  pl->speed = -(position[1] - 400.0) * sscale[ind];
  pl->rotate = (position[0] - 500.0) * rscale[ind];
  if (fabs(pl->speed) > 10.0)
    pl->speed = sign(10.0, pl->speed);
  if (fabs(pl->rotate) > 0.030)
    pl->rotate = sign(0.030, pl->rotate);
  scrot = pl->rotate * 10.0 / 0.030;
  sctot = sqrt(pl->speed*pl->speed + scrot*scrot);
  if (sctot > 10.0) {
    scale = 10.0 / sctot;
    pl->speed *= scale;
    pl->rotate *= scale;
  }
  if (draw) {
    gprsetrasterop(6);
    gprsetclippingactive(FALSE);
    if (!first) {
      gprbitblt(window, destorigin);
      gprsetdrawvalue(icol[0]);
      gprsetrasterop(3);
      multiline(stick, 2);
    }
    else {
      first = FALSE;
      gprsetrasterop(3);
    }
    gprsetdrawvalue(icol[1]);
    destorigin[0] =  35.0 * (pl->rotate / 0.03) + 845.0;
    destorigin[1] = -35.0 * (pl->speed  / 10.0)  + 550.0;
    gprbitblt(window, destorigin);
    xl = pl->rotate / 0.030;
    yl = pl->speed / 10.0;
    tl = sqrt(xl*xl + yl*yl);
    if (tl > 0.05) {
      yoff = xl / tl * 9.0;
      xoff = yl / tl * 9.0;
    }
    else {
      yoff = 0.0;
      xoff = 0.0;
    }
    stick[0] = 855;
    stick[2] = destorigin[0] + 10 + xoff / 2;
    stick[4] = 855;
    stick[6] = destorigin[0] + 10 - xoff / 2;
    stick[1] = 560;
    stick[3] = destorigin[1] + 10 + yoff / 2;;
    stick[5] = 560;
    stick[7] = destorigin[1] + 10 - yoff / 2;
    multiline(stick, 2);
    gprsetclippingactive(TRUE);
  }
  draw = !draw;
  pl->rotate = -pl->rotate;
}

/*
 * scanner
 *
 * draws the radar scan...
 *
 * status: 
 * should work with multiple enemies, need to test this...
 */
void scanner(o, opt)
     Genericp o;
     Optionp opt;
{
  static float scale = 0.03;
  static XSegment scanline[] = {500, 560, 500, 560};
  static logical init = TRUE;
  static XSegment* dot;
  static float ca = 1.0;        /* keep track of where the scanner line */
  static float sa = 0.0;        /* is currently positioned */
  static float sda = 0.087156;
  static float cda = 0.996195;
  static int ind = 0;           /* number of enemies last on scanner */
  float temp;
  Genericp g;
  XSegment* nextdot;
  XSegment* curdot;

  if (init) {
    dot = (XSegment*) malloc(sizeof(XSegment)*2*opt->mobjects);
    if (dot == NULL) {
      printf("Malloc failed...too many objects?\n");
      gprterminate();
      exit(1);
    }
    init = FALSE;
  }

  gprsetclippingactive(FALSE);
  gprsetdrawvalue(icol[0]);
  multiline(scanline, 1);    /* erase scan line */
  if (ind)                      /* erase enemies, if necessary */
    multiline(dot, ind);
  temp = ca;
  ca = ca * cda - sa * sda;
  sa = sa * cda + sda * temp;
  scanline->x2 = 60.0 * ca + 500;
  scanline->y2 = 60.0 * sa + 560;
  gprsetdrawvalue(icol[2]);
  multiline(scanline, 1);
  ind = 0;
  curdot = dot;
  for (g=o+opt->estart; g<o+opt->lstart; g++)
    if (g->attr & IS_ALIVE && g->range <= 2000.0 && g->range != 0.0) {
      nextdot = curdot + 1;
      nextdot->x1 = curdot->x1 = 500 + g->prox * scale - 1;
      nextdot->y2 = curdot->y1 =  560 - g->proy * scale + 1;
      nextdot->x2 = curdot->x2 = curdot->x1 + 2;
      nextdot->y1 = curdot->y2 = curdot->y1 - 2;
      ind += 2;
      curdot += 2;
    }
  if (ind)
    multiline(dot, ind);
  gprsetclippingactive(TRUE);
}

void xhairs (aligned)
     logical aligned;
{
  static logical last = FALSE;
  static short pt1[] = {500, 215, 500, 235, 500, 285, 500, 305, 475, 240,
                          475, 235, 475, 235, 525, 235, 525, 235, 525, 240,
                          475, 280, 475, 285, 475, 285, 525, 285, 525, 285,
                          525, 280};
  static short pt2[] = {500, 215, 500, 235, 500, 285, 500, 305, 475, 245,
                          500, 235, 500, 235, 525, 245, 475, 275, 500, 285,
                          500, 285, 525, 275};
  static logical draw = TRUE;
  if (draw) {
    if (aligned) 
      if (last) {
        gprsetdrawvalue(icol[1]);
        multiline(pt2, 6);
        last = TRUE;
      }
      else {
        gprsetdrawvalue(icol[0]);
        multiline(pt1, 8);
        gprsetdrawvalue(icol[1]);
        multiline(pt2, 6);
        last = TRUE;
      }
    else if (last) {
      gprsetdrawvalue(icol[0]);
      multiline(pt2, 6);
      gprsetdrawvalue(icol[14]);
      multiline(pt1, 8);
      last = FALSE;
    }
    else {
      gprsetdrawvalue(icol[14]);
      multiline(pt1, 8);
    }
  }
  draw = !draw;
}

void drawhorizon(azm)
     float azm;
{
  static short horizon[] = {500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240,
                              500, 240, 500, 240, 500, 240, 500, 240};
  short* current;
  static int number = 0;
  static float rdc = 0.01745329251;
  static float scale = 15.0;
  static int numclust[] = {8, 12, 10, 12, 10, 10};
  static int clustux[][12] = {150, 140, 150, 60, 85, -100, -50, -150, 0, 0,
                                0, 0, 150, 50, 75, 0, 0, 7, 0, -40, 0, -110,
                                -25, -150, 150, 115, 115, 105, 115, -10, 0,
                                -125, -85, -150, 0, 0, 150, 130, 150, 10, 25,
                                -35, -35, 0, -35, -140, -110, -150, 150, -10,
                                25, -70, -50, -125, -125, -100, -125, -150,
                                0, 0, 150, 100, 140, 0, 0, -30, 0, -120, -60,
                                -150, 0, 0};
  static int clustuy[][12] = {160, 220, 160, 250, 225, 245, 250, 240, 0, 0, 0,
                                0, 240, 227, 245, 190, 190, 215, 190, 225, 190,
                                213, 240, 200, 200, 189, 189, 225, 189, 244,
                                250, 165, 213, 135, 0, 0, 135, 200, 135, 210,
                                225, 165, 165, 230, 165, 228, 210, 215, 215,
                                217, 230, 195, 210, 150, 150, 210, 150, 173,
                                0, 0, 173, 209, 225, 170, 170, 225, 170, 230,
                                200, 160, 0, 0};

  static int pt[2], radius;
  float deg, degmin, degmax;
  logical flag1, flag2;
  int indmin, indmax, i, i1, j;
  float center, xoff;
  static logical moon = FALSE;
  
  gprsetdrawvalue(icol[0]);
  multiline(horizon, number);
  if (moon)
    gprcircle(pt, radius);
  gprsetdrawvalue(icol[14]);
  deg = azm / rdc;
  if (deg >= 360.0)
    deg -= 360.0;
  degmin = deg - 30.0;
  degmax = deg + 30.0;
  flag1 = FALSE;
  flag2 = FALSE;
  if (degmin < 0.0) {
    degmin += 360.0;
    flag1 = TRUE;
  }
  if (degmax >= 360.0) {
    degmax -= 360.0;
    flag2 = TRUE;
  }
  indmin = (int) (degmin / 20.0);
  indmax = (int) (degmax / 20.0) + 1;
  number = 0;
  current = horizon;
  if (!flag1 && !flag2)
    for (i=indmin; i<indmax; i++) {
      center = 10.0 + i * 20.0;
      xoff = (deg - center) * scale + 500.0;
      i1 = i % 6;
      for (j= 0; j<numclust[i1]; j++){
        *current++ = clustux[i1][j] + xoff;
        *current++ = clustuy[i1][j];
        number++;
      }
    }
  else if (flag1) {
    for (i= indmin; i<18; i++) {
      center = 10.0 + i * 20.0;
      xoff = (360.0 + deg - center) * scale + 500.0;
      i1 = i % 6;
      for (j=0; j<numclust[i1]; j++) {
        *current++ = clustux[i1][j] + xoff;
        *current++ = clustuy[i1][j];
        number++;
      }
    }
    for (i=0; i<indmax; i++) {
      center = 10.0 + i * 20.0;
      xoff = (deg - center) * scale + 500.0;
      i1 = i % 6;
      for (j=0; j<numclust[i1]; j++) {
        *current++ = clustux[i1][j] + xoff;
        *current++ = clustuy[i1][j];
        number++;
      }
    }
  }
  else {
    for (i=indmin; i<18; i++) {
      center = 10.0 + i * 20.0;
      xoff = (deg - center) * scale + 500.0;
      i1 = i % 6;
      for (j=0; j<numclust[i1]; j++) {
        *current++ = clustux[i1][j] + xoff;
        *current++ = clustuy[i1][j];
        number++;
      }
    }
    for (i=0; i<indmax; i++) {
      center = 10.0 + i * 20.0;
      xoff = (deg - 360.0 - center) * scale + 500.0;
      i1 = i % 6;
      for (j=0; j<numclust[i1]; j++) {
        *current++ = clustux[i1][j] + xoff;
        *current++ = clustuy[i1][j];
        number++;
      }
    }
  }
  number >>= 1;
  multiline(horizon, number);
  if (deg <= 360.0 && deg >= 270.0) {
    moon = TRUE;
    pt[0] = 500 + (deg - 315.0) * scale;
    pt[1] = 105;
    radius = 20;
    gprcircle(pt, radius);
  }
  else
    moon = FALSE;
}

void drawcracks()
{
  static short pt[] = {190, 75, 270, 175, 270, 175, 230, 265, 240, 243,
                         330, 290, 310, 280, 390, 235, 370, 246, 380, 195,
                         200, 425, 290, 365, 270, 378, 300, 325, 630, 425,
                         560, 335, 580, 361, 626, 295, 570, 348, 510, 355,
                         520, 354, 490, 275, 500, 301, 440, 290, 810, 75,
                         720, 125, 720, 125, 695, 205, 700, 200, 590, 210,
                         630, 206, 620, 256, 710, 157, 780, 245, 770, 232,
                         730, 305, 740, 287, 760, 315};
  gprsetdrawvalue(icol[1]);
  multiline(pt, 19);
}

void clearscreen ()
{
  static int destorigin[] = {70, 75};
  static int window[][2] = {70, 75, 860, 350};
  gprsetrasterop(6);
  gprbitblt(window, destorigin);
  gprsetrasterop(3);
  if (incolor) {
    gprsetrasterop(6);
    gprbitblt(window, destorigin);
    gprsetrasterop(3);
    gprsetrasterop(6);      
    gprbitblt(window, destorigin);
    gprsetrasterop(3);
    gprsetrasterop(6);      
    gprbitblt(window, destorigin);
    gprsetrasterop(3);
  }
}

void explodetank(g, pl)
     Genericp g;
     Genericp pl;
{
  float proux[3], prouy[3], check[3], range[3];
  float rx, ry, rz, prx, pry, prz;
  logical draw[3];
  static float sda[] = {0.087156, 0.087156, -0.087156};
  static float cda[] = {0.996195, 0.996195,  0.996195};
  static float sdp[] = {0.087156, 0.087156, -0.087156};
  static float cdp[] = {0.996195, 0.996195,  0.996195};
  static float gravity = 1.0;
  static float threshold =  0.8;
  static int musxm[] = {3, 3, -3, -3, -3, -3, 3, 3};
  static int musym[] = {-28, 28, -28, 28, -13, 28, -13, 28};
  static int muszm[] = {3, 3, 3, 3, -3, -3, -3, -3};
  static int musxp[] = {-3, 3, 3, -3};
  static int musyp[] = {28, 28, 28, 28};
  static int muszp[] = {-3, -3, 3, 3};
  static int turxp[] = {-10, -10, 10, 10, 25, 25, 10, -10, -25, -25, -10, 10};
  static int turyp[] = {-50, -18, -18, -50, -55, 55, -18, -18, 55, -55, -50,
                          -50};
  static int turzp[] = {10, 10, 10, 10, -11, -20, 10, 10, -20, -11, 10, 10};
  static int basxp[] = {30, 35, 35, 30, -30, -35, -35, -30, 30, 30};
  static int basyp[] = {-53, -60, 60, 37, 37, 60, -60, -53, -53, 37};
  static int baszp[] = {-15, 15, -5, -15, -15, -5, 15, -15, -15, -15};
  static int basxm[] = {35, -35, 35, -35, -30, -30};
  static int basym[] = {-60, -60, 60, 60, -53, 37};
  static int baszm[] = {15, 15, -5, -5, -15, -15};
  static float yoffset[] = {0.0, 5.0, 32.0};
  static float zoffset[] = {-25.0, 0.0, 0.0};
  int i, color;
  float dx, dy, dz, xn, yn, zn, cn, sn, cp, sp, temp;
  
  gprsetdrawvalue(icol[0]);
  if (g->last[0]) {
    polyline(g->pline[0][0], 10);
    multiline(g->mline[0][0], 3);
  }
  if (g->last[1]) {
    polyline(g->pline[1][0], 12);
  }
  if (g->last[2]) {
    multiline(g->mline[1][0], 4);
    polyline(g->pline[2][0], 5);
  }
  if (g->attr & EXERASE || g->ecount >= 40) {
    g->attr = 0;
    return;
  }
  if (g->attr & IS_NEW) {
    g->attr &= ~IS_NEW;
    g->cta[0] = cos(g->azm);
    g->sta[0] = sin(g->azm);
    g->ctp[0] = 1.0;
    g->stp[0] = 0.0;
    for (i=1; i<3; i++) {
      g->cta[i] = g->cta[0];
      g->sta[i] = g->sta[0];
      g->ctp[i] = 1.0;
      g->stp[i] = 0.0;
    }
    for (i=0; i<3; i++) {
      g->pos[0][i] = -yoffset[i] * g->sta[0];
      g->pos[1][i] =  yoffset[i] * g->cta[0];
      g->pos[2][i] =  zoffset[i];
    }
    for (i=0; i<3; i++) {
      g->vel[0][i] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[0][i] = - g->vel[0][i];
      g->vel[1][i] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[1][i] = - g->vel[1][i];
      g->vel[2][i] = 12.5 + frand() * 7.5;
    }
  }
  for (i=0; i<3; i++) {
    dx = g->x + g->pos[0][i] - pl->x;
    dy = g->y + g->pos[1][i] - pl->y;
    range[i] = sqrt(dx*dx + dy*dy);
    if (range[i] < 2000.0) {
      prouy[i] = -dx * pl->sa + dy * pl->ca;
      proux[i] =  dx * pl->ca + dy * pl->sa;           
      check[i] =  prouy[i] / (fabs(proux[i]) + 1.0);
      if (check[i] > threshold)
        draw[i] = TRUE;
      else
        draw[i] = FALSE;
    }
    else
      draw[i] = FALSE;
  }
  if (draw[0]) {
    dx = pl->x - g->x - g->pos[0][0];
    dy = pl->y - g->y - g->pos[1][0];
    dz = - g->pos[2][0];
    xn =  dx * g->cta[0]          + dy * g->sta[0];
    yn = -dx * g->sta[0] * g->ctp[0] +
      dy * g->cta[0] * g->ctp[0] + dz * g->stp[0];
    zn =  dx * g->sta[0] * g->stp[0] -
      dy * g->cta[0] * g->stp[0] + dz * g->ctp[0];
    cn = pl->ca * g->cta[0] + pl->sa * g->sta[0];
    sn = pl->sa * g->cta[0] - pl->ca * g->sta[0];
    cp = g->ctp[0];
    sp = -g->stp[0];
    for (i=0; i<6; i++) {
      rx =  basxm[i] - xn;
      ry =  basym[i] - yn;
      rz =  baszm[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[0][i][0] = 500 + prx / pry * 450;
      g->mline[0][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<10; i++) {
      rx =  basxp[i] - xn;
      ry =  basyp[i] - yn;
      rz =  baszp[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - prz / pry * 450;
    }
    g->last[0] = TRUE;
    color = range[0] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[0][0], 10);
    multiline(g->mline[0][0], 3);
  }
  else
    g->last[0] = FALSE;
  if (draw[1]) {
    dx = pl->x - g->x - g->pos[0][1];
    dy = pl->y - g->y - g->pos[1][1];
    dz = - g->pos[2][1];
    xn =  dx * g->cta[1]          + dy * g->sta[1];
    yn = -dx * g->sta[1] * g->ctp[1] +
      dy * g->cta[1] * g->ctp[1] + dz * g->stp[1];
    zn =  dx * g->sta[1] * g->stp[1] -
      dy * g->cta[1] * g->stp[1] + dz * g->ctp[1];
    cn = pl->ca * g->cta[1] + pl->sa * g->sta[1];
    sn = pl->sa * g->cta[1] - pl->ca * g->sta[1];
    cp = g->ctp[1];
    sp = -g->stp[1];
    for (i=0; i<12; i++) {
      rx =  turxp[i] - xn;
      ry =  turyp[i] - yn;
      rz =  turzp[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[1][i][0] = 500 + prx / pry * 450;
      g->pline[1][i][1] = 260 - prz / pry * 450;
    }
    g->last[1] = TRUE;
    color = range[1] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[1][0], 12);
  }
  else
    g->last[1] = FALSE;
  if (draw[2]) {
    dx = pl->x - g->x - g->pos[0][2];
    dy = pl->y - g->y - g->pos[1][2];
    dz = - g->pos[2][2];
    xn =  dx * g->cta[2]          + dy * g->sta[2];
    yn = -dx * g->sta[2] * g->ctp[2] +
      dy * g->cta[2] * g->ctp[2] + dz * g->stp[2];
    zn =  dx * g->sta[2] * g->stp[2] -
      dy * g->cta[2] * g->stp[2] + dz * g->ctp[2];
    cn = pl->ca * g->cta[2] + pl->sa * g->sta[2];
    sn = pl->sa * g->cta[2] - pl->ca * g->sta[2];
    cp = g->ctp[2];
    sp = -g->stp[2];
    for (i=0; i<8; i++) {
      rx =  musxm[i] - xn;
      ry =  musym[i] - yn;
      rz =  muszm[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[1][i][0] = 500 + prx / pry * 450;
      g->mline[1][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<4; i++) {
      rx =  musxp[i] - xn;
      ry =  musyp[i] - yn;
      rz =  muszp[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[2][i][0] = 500 + prx / pry * 450;
      g->pline[2][i][1] = 260 - prz / pry * 450;
    }
    g->pline[2][i][0] = g->pline[2][0][0];
    g->pline[2][i][1] = g->pline[2][0][1];
    g->last[2] = TRUE;
    color = range[2] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    multiline(g->mline[1][0], 4);
    polyline(g->pline[2][0], 5);
  }
  else
    g->last[2] = FALSE;
  for (i=0; i<3; i++) {
    g->pos[0][i] = g->pos[0][i] + g->vel[0][i];
    g->pos[1][i] = g->pos[1][i] + g->vel[1][i];
    g->vel[2][i] = g->vel[2][i] - gravity;
    g->pos[2][i] = g->pos[2][i] + g->vel[2][i];
    if (g->pos[2][i] < -40.0) {
      g->pos[2][i] = -40.0;
      g->vel[2][i] = -0.2 * g->vel[2][i];
    }
    temp = g->cta[i];
    g->cta[i] = g->cta[i] * cda[i] - g->sta[i] * sda[i];
    g->sta[i] = g->sta[i] * cda[i] + sda[i] * temp;
    temp = g->ctp[i];
    g->ctp[i] = g->ctp[i] * cdp[i] - g->stp[i] * sdp[i];
    g->stp[i] = g->stp[i] * cdp[i] + sdp[i] * temp;
  }
}

void explodesuper (g, pl)
     Genericp g;
     Genericp pl;
{
  float proux[3], prouy[3], check[3], range[3];
  float rx, ry, rz, prx, pry, prz;
  logical draw[3];
  static float sda[] = {0.087156, 0.087156, -0.087156};
  static float cda[] = {0.996195, 0.996195, 0.996195};
  static float sdp[] = {0.087156, 0.087156, -0.087156};
  static float cdp[] = {0.996195, 0.996195, 0.996195};
  static float gravity = 1.0;
  static float threshold = 0.8;
  static int musxm[] = {3, 3, -3, -3, 3, 3, -3, -3};
  static int musym[] = {-36, 36, -36, 36, -27, 36, -27, 36};
  static int muszm[] = {0, 0, 0, 0, -6, -6, -6, -6};
  static int musxp[] = {3, 3, -3, -3};
  static int musyp[] = {36, 36, 36, 36};
  static int muszp[] = {-6, 0, 0, -6};
  static int turxp[] = {0, 13, 11, 11, 0, -13, -11, -11, 0};
  static int turyp[] = {47, -48, -48, -13, 47, -48, -48, -13, 47};
  static int turzp[] = {-18, 9, 19, 19, -18, 9, 19, 19, -18};
  static int turxm[] = {11, -11, 11, -11};
  static int turym[] = {-48, -48, -13, -13};
  static int turzm[] = {19, 19, 19, 19};
  static int basxp[] = {15, 30, 30, 15, -15, -30, -30, -15};
  static int basyp[] = {60, -60, -60, 60, 60, -60, -60, 60};
  static int baszp[] = {-15, -15, 19, -15, -15, -15, 19, -15};
  static int basxm[] = {-30, 30, -30, 30};
  static int basym[] = {-60, -60, -60, -60};
  static int baszm[] = {19, 19, -15, -15};
  static float yoffset[] = {0.0, -12.0, 19.0};
  static float zoffset[] = {-25.0, -15.0, 0.0};
  int i, color;
  float dx, dy, dz, xn, yn, zn, cn, sn, cp, sp, temp;
  
  gprsetdrawvalue(icol[0]);
  if (g->last[0]) {
    polyline(g->pline[0][0], 8);
    multiline(g->mline[0][0], 2);
  }
  if (g->last[1]) {
    polyline(g->pline[1][0], 9);
    multiline(g->mline[1][0], 2);
  }
  if (g->last[2]) {
    multiline(g->mline[2][0], 4);
    polyline(g->pline[2][0], 5);
  }
  if (g->attr & EXERASE || g->ecount >= 40) {
    g->attr = 0;
    return;
  }
  if (g->attr & IS_NEW) {
    g->attr &= ~IS_NEW;
    g->cta[0] = cos(g->azm);
    g->sta[0] = sin(g->azm);
    g->ctp[0] = 1.0;
    g->stp[0] = 0.0;
    for (i=1; i<3; i++) {
      g->cta[i] = g->cta[0];
      g->sta[i] = g->sta[0];
      g->ctp[i] = 1.0;
      g->stp[i] = 0.0;
    }
    for (i=0; i<3; i++) {
      g->pos[0][i] = -yoffset[i] * g->sta[0];
      g->pos[1][i] =  yoffset[i] * g->cta[0];
      g->pos[2][i] =  zoffset[i];
    }
    for (i=0; i<3; i++) {
      g->vel[0][i] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[0][i] = - g->vel[0][i];
      g->vel[1][i] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[1][i] = - g->vel[1][i];
      g->vel[2][i] = 12.5 + frand() * 7.5;
    }
  }
  for (i=0; i<3; i++) {
    dx = g->x + g->pos[0][i] - pl->x;
    dy = g->y + g->pos[1][i] - pl->y;
    range[i] = sqrt(dx*dx + dy*dy);
    if (range[i] < 2000.0) {
      prouy[i] = -dx * pl->sa + dy * pl->ca;
      proux[i] =  dx * pl->ca + dy * pl->sa;           
      check[i] =  prouy[i] / (fabs(proux[i]) + 1.0);
      if (check[i] > threshold) 
        draw[i] = TRUE;
      else
        draw[i] = FALSE;
    }
    else
      draw[i] = FALSE;
  }
  if (draw[0]) {
    dx = pl->x - g->x - g->pos[0][0];
    dy = pl->y - g->y - g->pos[1][0];
    dz = - g->pos[2][0];
    xn =  dx * g->cta[0]          + dy * g->sta[0];
    yn = -dx * g->sta[0] * g->ctp[0] +
      dy * g->cta[0] * g->ctp[0] + dz * g->stp[0];
    zn =  dx * g->sta[0] * g->stp[0] -
      dy * g->cta[0] * g->stp[0] + dz * g->ctp[0];
    cn = pl->ca * g->cta[0] + pl->sa * g->sta[0];
    sn = pl->sa * g->cta[0] - pl->ca * g->sta[0];
    cp = g->ctp[0];
    sp = -g->stp[0];
    for (i=0; i<4; i++) {
      rx =  basxm[i] - xn;
      ry =  basym[i] - yn;
      rz =  baszm[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[0][i][0] = 500 + prx / pry * 450;
      g->mline[0][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<8; i++) {
      rx =  basxp[i] - xn;
      ry =  basyp[i] - yn;
      rz =  baszp[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - prz / pry * 450;
    }
    g->last[0] = TRUE;
    color = range[0] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[0][0], 8);
    multiline(g->mline[0][0], 2);
  }
  else
    g->last[0] = FALSE;
  if (draw[1]) {
    dx = pl->x - g->x - g->pos[0][1];
    dy = pl->y - g->y - g->pos[1][1];
    dz = - g->pos[2][1];
    xn =  dx * g->cta[1]          + dy * g->sta[1];
    yn = -dx * g->sta[1] * g->ctp[1] +
      dy * g->cta[1] * g->ctp[1] + dz * g->stp[1];
    zn =  dx * g->sta[1] * g->stp[1] -
      dy * g->cta[1] * g->stp[1] + dz * g->ctp[1];
    cn = pl->ca * g->cta[1] + pl->sa * g->sta[1];
    sn = pl->sa * g->cta[1] - pl->ca * g->sta[1];
    cp = g->ctp[1];
    sp = -g->stp[1];
    for (i=0; i<9; i++) {
      rx =  turxp[i] - xn;
      ry =  turyp[i] - yn;
      rz =  turzp[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[1][i][0] = 500 + prx / pry * 450;
      g->pline[1][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<4; i++) {
      rx =  turxm[i] - xn;
      ry =  turym[i] - yn;
      rz =  turzm[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[1][i][0] = 500 + prx / pry * 450;
      g->mline[1][i][1] = 260 - prz / pry * 450;
    }
    g->last[1] = TRUE;
    color = range[1] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[1][0], 9);
    multiline(g->mline[1][0], 2);
  }
  else
    g->last[1] = FALSE;
  if (draw[2]) {
    dx = pl->x - g->x - g->pos[0][2];
    dy = pl->y - g->y - g->pos[1][2];
    dz = - g->pos[2][2];
    xn =  dx * g->cta[2]          + dy * g->sta[2];
    yn = -dx * g->sta[2] * g->ctp[2] + dy * g->cta[2] * g->ctp[2] + dz * g->stp[2];
    zn =  dx * g->sta[2] * g->stp[2] - dy * g->cta[2] * g->stp[2] + dz * g->ctp[2];
    cn = pl->ca * g->cta[2] + pl->sa * g->sta[2];
    sn = pl->sa * g->cta[2] - pl->ca * g->sta[2];
    cp = g->ctp[2];
    sp = -g->stp[2];
    for (i=0; i<8; i++) {
      rx =  musxm[i] - xn;
      ry =  musym[i] - yn;
      rz =  muszm[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[2][i][0] = 500 + prx / pry * 450;
      g->mline[2][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<4; i++) {
      rx =  musxp[i] - xn;
      ry =  musyp[i] - yn;
      rz =  muszp[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[2][i][0] = 500 + prx / pry * 450;
      g->pline[2][i][1] = 260 - prz / pry * 450;
    }
    g->pline[2][i][0] = g->pline[2][0][0];
    g->pline[2][i][1] = g->pline[2][0][1];
    g->last[2] = TRUE;
    color = range[2] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    multiline(g->mline[2][0], 4);
    polyline(g->pline[2][0], 5);
  }
  else
    g->last[2] = FALSE;
  for (i=0; i<3; i++) {
    g->pos[0][i] = g->pos[0][i] + g->vel[0][i];
    g->pos[1][i] = g->pos[1][i] + g->vel[1][i];
    g->vel[2][i] = g->vel[2][i] - gravity;
    g->pos[2][i] = g->pos[2][i] + g->vel[2][i];
    if (g->pos[2][i] < -40.0) {
      g->pos[2][i] = -40.0;
      g->vel[2][i] = -0.2 * g->vel[2][i];
    }
    temp = g->cta[i];
    g->cta[i] = g->cta[i] * cda[i] - g->sta[i] * sda[i];
    g->sta[i] = g->sta[i] * cda[i] + sda[i] * temp;
    temp = g->ctp[i];
    g->ctp[i] = g->ctp[i] * cdp[i] - g->stp[i] * sdp[i];
    g->stp[i] = g->stp[i] * cdp[i] + sdp[i] * temp;
  }
}

void explodecopter (g, pl)
     Genericp g;
     Genericp pl;
{
  float proux[3], prouy[3], check[3], range[3];
  float rx, ry, rz, prx, pry, prz;
  logical draw[3];
  static float sda[] = {0.573576, 0.087156, -0.087156};
  static float cda[] = {0.819152, 0.996195,  0.996195};
  static float sdp[] = {0.087156, 0.087156, -0.087156};
  static float cdp[] = {0.996195, 0.996195,  0.996195};
  static float gravity = 1.0;
  static float threshold = 0.8;
  static int proxp[] = {6, 6, -6, 6, -6};
  static int proyp[] = {100, 100, -100, -100, 100};
  static int prozp[] = {0, 0, 0, 0, 0};
  static int talxp[] = {0, 7, 10, 0, 0, 0, 0, 0, -7, -10, 0};
  static int talyp[] = {-32, 52, 48, -34, -52, -62, -48, -32, 52, 48, -34};
  static int talzp[] = {-10, -34, -14, 0, 28, 28, -10, -10, -34, -14, 0};
  static int bodxp[] = {-14, 14, 0, -14, -7, 7, 14, 26, 0, -26, -10, 10, 
                          26, 4, 0, -4, -4, 4, 4};
  static int bodyp[] = {34, 34, 60, 34, -30, -30, 34, 34, 60, 34, -34,
                          -34, 34, 20, 22, 20, -22, -22, 20};
  static int bodzp[] = {-34, -34, -14, -34, -34, -34, -34, -14, -14, -14,
                          -14, -14, -14, 16, 16, 16, 16, 16, 16};
  static int bodxm[] = {-10, -4, 10, 4, 0, 0, -14, -26, -26, -4};
  static int bodym[] = {-34, -22, -34, -22, 22, 60, 34, 34, 34, 20};
  static int bodzm[] = {-14, 16, -14, 16, 16, -14, -34, -14, -14, 16};
  static float yoffset[] = {0.0, -82.0, 0.0};
  static float zoffset[] = {30.0, 0.0, 0.0};
  int i, color;
  float dx, dy, dz, xn, zn, c1, s1, c2, s2, cp, sp, t1, t2;
  float t3, t4, t5, t6, t7, t8, t9, cn, sn, yn, temp;
  
  gprsetdrawvalue(icol[0]);
  if (g->last[0]) {
    polyline(g->pline[0][0], 6);
  }
  if (g->last[1]) {
    polyline(g->pline[1][0], 11);
  }
  if (g->last[2]) {
    polyline(g->pline[2][0], 19);
    multiline(g->mline[0][0], 5);
  }
  if (g->attr & EXERASE || g->ecount >= 40) {
    g->attr = 0;
    return;
  }
  if (g->attr & IS_NEW) {
    g->attr &= ~IS_NEW;
    g->cta[0] = cos(g->azm);
    g->sta[0] = sin(g->azm);
    g->ctp[0] = 1.0;
    g->stp[0] = 0.0;
    for (i=1; i<3; i++) {
      g->cta[i] = g->cta[0];
      g->sta[i] = g->sta[0];
      g->ctp[i] = 1.0;
      g->stp[i] = 0.0;
    }
    for (i=0; i<3; i++) {
      g->pos[0][i] = -yoffset[i] * g->sta[0];
      g->pos[1][i] = yoffset[i] * g->cta[0];
      g->pos[2][i] = g->z + zoffset[i];
    }
    for (i=0; i<3; i++) {
      g->vel[0][i] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[0][i] = - g->vel[0][i];
      g->vel[1][i] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[1][i] = - g->vel[1][i];
      g->vel[2][i] = 12.5 + frand() * 7.5;
    }
    g->vel[2][0] = g->vel[2][0] + 6.0;
  }
  for (i=0; i<3; i++) {
    dx = g->x + g->pos[0][i] - pl->x;
    dy = g->y + g->pos[1][i] - pl->y;
    range[i] = sqrt(dx*dx + dy*dy);
    if (range[i] < 2000.0) {
      prouy[i] = -dx * pl->sa + dy * pl->ca;
      proux[i] =  dx * pl->ca + dy * pl->sa;           
      check[i] =  prouy[i] / (fabs(proux[i]) + 1.0);
      if (check[i] > threshold) 
        draw[i] = TRUE;
      else
        draw[i] = FALSE;
    }
    else
      draw[i] = FALSE;
  }
  if (draw[0]) {
    dx = pl->x - g->x - g->pos[0][0];
    dy = pl->y - g->y - g->pos[1][0];
    dz = - g->pos[2][0];
    xn =  dx * g->cta[0] +
      dy * g->sta[0] * g->ctp[0] + dz * g->sta[0] * g->stp[0];
    yn = -dx * g->sta[0] +
      dy * g->cta[0] * g->ctp[0] + dz * g->cta[0] * g->stp[0];
    zn =              - dy * g->stp[0]          + dz * g->ctp[0];
    c1 = pl->ca * g->cta[0];
    s1 = pl->sa * g->sta[0];
    c2 = pl->ca * g->sta[0];
    s2 = pl->sa * g->cta[0];
    cp = g->ctp[0];
    sp = g->stp[0];
    t1 = c1 + s1 * cp;
    t2 = -c2 + s2 * cp;
    t3 = -pl->sa * sp;
    t4 = -s2 + c2 * cp;
    t5 = s1 + c1 * cp;
    t6 = -pl->ca * sp;
    t7 = g->sta[0] * sp;
    t8 = g->cta[0] * sp;
    t9 = cp;
    for (i=0; i<5; i++) {
      rx = proxp[i] - xn;
      ry = proyp[i] - yn;
      rz = prozp[i] - zn;
      prx = rx * t1 + ry * t2 + rz * t3;
      pry = rx * t4 + ry * t5 + rz * t6;
      prz = rx * t7 + ry * t8 + rz * t9;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - prz / pry * 450;
    }
    g->pline[0][i][0] = g->pline[0][0][0];
    g->pline[0][i][1] = g->pline[0][0][1];
    g->last[0] = TRUE;
    color = range[0] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[0][0], 6);
  }
  else
    g->last[0] = FALSE;
  if (draw[1]) {
    dx = pl->x - g->x - g->pos[0][1];
    dy = pl->y - g->y - g->pos[1][1];
    dz = - g->pos[2][1];
    xn =  dx * g->cta[1]          + dy * g->sta[1];
    yn = -dx * g->sta[1] * g->ctp[1] +
      dy * g->cta[1] * g->ctp[1] + dz * g->stp[1];
    zn =  dx * g->sta[1] * g->stp[1] -
      dy * g->cta[1] * g->stp[1] + dz * g->ctp[1];
    cn = pl->ca * g->cta[1] + pl->sa * g->sta[1];
    sn = pl->sa * g->cta[1] - pl->ca * g->sta[1];
    cp = g->ctp[1];
    sp = -g->stp[1];
    for (i=0; i<11; i++) {
      rx = talxp[i] - xn;
      ry = talyp[i] - yn;
      rz = talzp[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[1][i][0] = 500 + prx / pry * 450;
      g->pline[1][i][1] = 260 - prz / pry * 450;
    }
    g->last[1] = TRUE;
    color = range[1] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[1][0], 11);
  }
  else
    g->last[1] = FALSE;
  if (draw[2]) {
    dx = pl->x - g->x - g->pos[0][2];
    dy = pl->y - g->y - g->pos[1][2];
    dz = - g->pos[2][2];
    xn =  dx * g->cta[2]          + dy * g->sta[2];
    yn = -dx * g->sta[2] * g->ctp[2] +
      dy * g->cta[2] * g->ctp[2] + dz * g->stp[2];
    zn =  dx * g->sta[2] * g->stp[2] -
      dy * g->cta[2] * g->stp[2] + dz * g->ctp[2];
    cn = pl->ca * g->cta[2] + pl->sa * g->sta[2];
    sn = pl->sa * g->cta[2] - pl->ca * g->sta[2];
    cp = g->ctp[2];
    sp = -g->stp[2];
    for (i=0; i<19; i++) {
      rx = bodxp[i] - xn;
      ry = bodyp[i] - yn;
      rz = bodzp[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[2][i][0] = 500 + prx / pry * 450;
      g->pline[2][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<10; i++) {
      rx = bodxm[i] - xn;
      ry = bodym[i] - yn;
      rz = bodzm[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[0][i][0] = 500 + prx / pry * 450;
      g->mline[0][i][1] = 260 - prz / pry * 450;
    }
    g->last[2] = TRUE;
    color = range[2] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[2][0], 19);
    multiline(g->mline[0][0], 5);
  }
  else
    g->last[2] = FALSE;
  for (i=0; i<3; i++) {
    g->pos[0][i] = g->pos[0][i] + g->vel[0][i];
    g->pos[1][i] = g->pos[1][i] + g->vel[1][i];
    g->vel[2][i] = g->vel[2][i] - gravity;
    g->pos[2][i] = g->pos[2][i] + g->vel[2][i];
    if (g->pos[2][i] < -40.0) {
      g->pos[2][i] = -40.0;
      g->vel[2][i] = -0.2 * g->vel[2][i];
    }
    temp = g->cta[i];
    g->cta[i] = g->cta[i] * cda[i] - g->sta[i] * sda[i];
    g->sta[i] = g->sta[i] * cda[i] + sda[i] * temp;
    temp = g->ctp[i];
    g->ctp[i] = g->ctp[i] * cdp[i] - g->stp[i] * sdp[i];
    g->stp[i] = g->stp[i] * cdp[i] + sdp[i] * temp;
  }
}

void explodemissile (g, pl)
     Genericp g;
     Genericp pl;
{
  float proux[4], prouy[4], check[4], range[4];
  float rx, ry, rz, prx, pry, prz;
  logical draw[4];
  static int capx[] = {15, 25, 0, 15, -15, 0, 15, -15, 0, -25, -15};
  static int capy[] = {-30, -30, -45, -30, -30, -45, -30, -30, -45,
                         -30, -30};                                    
  static int capz[] = {-25, 0, 0, -25, -25, 0, 25, 25, 0, 0, 25};
  static int conx[] = {15, 0, 25, 15, 0, -15, -25, 0, -15};
  static int cony[] = {-30, 50, -30, -30, 50, -30, -30, 50, -30};
  static int conz[] = {-25, 0, 0, 25, 0, -25, 0, 0, 25};
  static int finx[] = {13, 15, 23, 23};
  static int finy[] = {-17, -30, -38, 0};
  static int finz[] = {11, 5, -10, -10};
  static float offset[] = {0.0, 0.0, -30.0, -30.0};
  static float sda[] = {0.087156, 0.087156, -0.087156, -0.087156};
  static float cda[] = {0.996195, 0.996195, 0.996195, 0.996195};
  static float sdp[] = {0.087156, 0.087156, -0.087156, -0.087156};
  static float cdp[] = {0.996195, 0.996195, 0.996195, 0.996195};
  static float gravity = 1.0;
  static float threshold = 0.8;
  int i, color;
  float dx, dy, dz, xn, yn, zn, cn, sn, cp, sp, temp;
  
  gprsetdrawvalue(icol[0]);
  if (g->last[0]) {
    polyline(g->pline[0][0], 11);
  }
  if (g->last[1]) {
    polyline(g->pline[1][0], 9);
  }
  if (g->last[2]) {
    polyline(g->pline[2][0], 5);
  }
  if (g->last[3]) {
    polyline(g->pline[3][0], 5);
  }
  if (g->attr & EXERASE || g->ecount >= 40) {
    g->attr = 0;
    return;
  }
  if (g->attr & IS_NEW) {
    g->attr &= ~IS_NEW;
    g->cta[0] = cos(g->azm);
    g->sta[0] = sin(g->azm);
    g->ctp[0] = 1.0;
    g->stp[0] = 0.0;
    for (i=1; i<4; i++) {
      g->cta[i] = g->cta[0];
      g->sta[i] = g->sta[0];
      g->ctp[i] = 1.0;
      g->stp[i] = 0.0;
    }
    for (i=0; i<4; i++) {
      g->pos[0][i] = 0.0;
      g->pos[1][i] = 0.0;
      g->pos[2][i] = g->z + offset[i];
    }
    for (i=0; i<4; i++) {
      g->vel[0][i] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[0][i] = - g->vel[0][i];
      g->vel[1][i] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[1][i] = - g->vel[1][i];
      g->vel[2][i] = 12.5 + frand() * 7.5;
    }
  }
  for (i=0; i<4; i++) {
    dx = g->x + g->pos[0][i] - pl->x;
    dy = g->y + g->pos[1][i] - pl->y;
    range[i] = sqrt(dx*dx + dy*dy);
    if (range[i] < 2000.0) {
      prouy[i] = -dx * pl->sa + dy * pl->ca;
      proux[i] =  dx * pl->ca + dy * pl->sa;           
      check[i] =  prouy[i] / (fabs(proux[i]) + 1.0);
      if (check[i] > threshold)
        draw[i] = TRUE;
      else
        draw[i] = FALSE;
    }
    else
      draw[i] = FALSE;
  }
  if (draw[0]) {
    dx = pl->x - g->x - g->pos[0][0];
    dy = pl->y - g->y - g->pos[1][0];
    dz = - g->pos[2][0];
    xn =  dx * g->cta[0]          + dy * g->sta[0];
    yn = -dx * g->sta[0] * g->ctp[0] +
      dy * g->cta[0] * g->ctp[0] + dz * g->stp[0];
    zn =  dx * g->sta[0] * g->stp[0] -
      dy * g->cta[0] * g->stp[0] + dz * g->ctp[0];
    cn = pl->ca * g->cta[0] + pl->sa * g->sta[0];
    sn = pl->sa * g->cta[0] - pl->ca * g->sta[0];
    cp = g->ctp[0];
    sp = -g->stp[0];
    for (i=0; i<11; i++) {
      rx =  capx[i] - xn;
      ry =  capy[i] - yn;
      rz =  capz[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - prz / pry * 450;
    }
    g->last[0] = TRUE;
    color = range[0] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[0][0], 11);
  }
  else
    g->last[0] = FALSE;
  if (draw[1]) {
    dx = pl->x - g->x - g->pos[0][1];
    dy = pl->y - g->y - g->pos[1][1];
    dz = - g->pos[2][1];
    xn =  dx * g->cta[1]          + dy * g->sta[1];
    yn = -dx * g->sta[1] * g->ctp[1] +
      dy * g->cta[1] * g->ctp[1] + dz * g->stp[1];
    zn =  dx * g->sta[1] * g->stp[1] -
      dy * g->cta[1] * g->stp[1] + dz * g->ctp[1];
    cn = pl->ca * g->cta[1] + pl->sa * g->sta[1];
    sn = pl->sa * g->cta[1] - pl->ca * g->sta[1];
    cp = g->ctp[1];
    sp = -g->stp[1];
    for (i=0; i<9; i++) {
      rx =  conx[i] - xn;
      ry =  cony[i] - yn;
      rz =  conz[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[1][i][0] = 500 + prx / pry * 450;
      g->pline[1][i][1] = 260 - prz / pry * 450;
    }
    g->last[1] = TRUE;
    color = range[1] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[1][0], 9);
  }
  else
    g->last[1] = FALSE;
  if (draw[2]) {
    dx = pl->x - g->x - g->pos[0][2];
    dy = pl->y - g->y - g->pos[1][2];
    dz = - g->pos[2][2];
    xn =  dx * g->cta[2]          + dy * g->sta[2];
    yn = -dx * g->sta[2] * g->ctp[2] +
      dy * g->cta[2] * g->ctp[2] + dz * g->stp[2];
    zn =  dx * g->sta[2] * g->stp[2] -
      dy * g->cta[2] * g->stp[2] + dz * g->ctp[2];
    cn = pl->ca * g->cta[2] + pl->sa * g->sta[2];
    sn = pl->sa * g->cta[2] - pl->ca * g->sta[2];
    cp = g->ctp[2];
    sp = -g->stp[2];
    for (i=0; i<4; i++) {
      rx =  finx[i] - xn;
      ry =  finy[i] - yn;
      rz =  finz[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[2][i][0] = 500 + prx / pry * 450;
      g->pline[2][i][1] = 260 - prz / pry * 450;
    }
    g->pline[2][i][0] = g->pline[2][0][0];
    g->pline[2][i][1] = g->pline[2][0][1];
    g->last[2] = TRUE;
    color = range[2] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[2][0], 5);
  }
  else
    g->last[2] = FALSE;
  if (draw[3]) {
    dx = pl->x - g->x - g->pos[0][3];
    dy = pl->y - g->y - g->pos[1][3];
    dz = - g->pos[2][3];
    xn =  dx * g->cta[3]          + dy * g->sta[3];
    yn = -dx * g->sta[3] * g->ctp[3] +
      dy * g->cta[3] * g->ctp[3] + dz * g->stp[3];
    zn =  dx * g->sta[3] * g->stp[3] -
      dy * g->cta[3] * g->stp[3] + dz * g->ctp[3];
    cn = pl->ca * g->cta[3] + pl->sa * g->sta[3];
    sn = pl->sa * g->cta[3] - pl->ca * g->sta[3];
    cp = g->ctp[3];
    sp = -g->stp[3];
    for (i=0; i<4; i++) {
      rx = -finx[i] - xn;
      ry =  finy[i] - yn;
      rz =  finz[i] - zn;
      prx =  rx * cn + ry * sn * cp + rz * sn * sp;
      pry = -rx * sn + ry * cn * cp + rz * cn * sp;
      prz =          - ry * sp      + rz * cp;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[3][i][0] = 500 + prx / pry * 450;
      g->pline[3][i][1] = 260 - prz / pry * 450;
    }
    g->pline[3][i][0] = g->pline[3][0][0];
    g->pline[3][i][1] = g->pline[3][0][1];
    g->last[3] = TRUE;
    color = range[3] / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[3][0], 5);
  }
  else
    g->last[3] = FALSE;
  for (i=0; i<4; i++) {
    g->pos[0][i] = g->pos[0][i] + g->vel[0][i];
    g->pos[1][i] = g->pos[1][i] + g->vel[1][i];
    g->vel[2][i] = g->vel[2][i] - gravity;
    g->pos[2][i] = g->pos[2][i] + g->vel[2][i];
    if (g->pos[2][i] < -40.0) {
      g->pos[2][i] = -40.0;
      g->vel[2][i] = -0.2 * g->vel[2][i];
    }
    temp = g->cta[i];
    g->cta[i] = g->cta[i] * cda[i] - g->sta[i] * sda[i];
    g->sta[i] = g->sta[i] * cda[i] + sda[i] * temp;
    temp = g->ctp[i];
    g->ctp[i] = g->ctp[i] * cdp[i] - g->stp[i] * sdp[i];
    g->stp[i] = g->stp[i] * cdp[i] + sdp[i] * temp;
  }
}

void explodelander(g, pl)
     Genericp g;
     Genericp pl;
{
  static int xp[] = {0, 80, 40, -40, -80, 0, 0, 0, 0, 0, 0, -57, -28,
                       28, 57, 0, 57, 28, -28, -57, 0};
  static int yp[] = {0, 0, 0, 0, 0, 0, 80, 40, -40, -80, 0, -57, -28,
                       28, 57, 0, -57, -28, 28, 57, 0};
  static int zp[] = {20, -20, -40, -40, -20, 20, -20, -40, -40, -20, 20,
                       -20, -40, -40, -20, 20, -20, -40, -40, -20, 20};
  static float sda = 0.087156;
  static float cda = 0.996195;
  float temp, dx, dy, xn, yn, cn, sn, rx, ry, prx, pry;
  int i, color;

  /* when hit the lander is drawn for 1 count, then erased
     for 2 counts....repeat as needed */
  if (g->last[0]) {
    gprsetdrawvalue(icol[0]);
    polyline(g->pline[0][0], 21);
  }
  if (g->attr & EXERASE || g->ecount >= 40) {
    g->attr = 0;
    return;
  }
  if (g->attr & IS_SEEN && g->ccount%3 == 0 ) {
    g->ccount = 0;
    temp = g->cta[0];
    g->cta[0] = g->cta[0] * cda - g->sta[0] * sda;
    g->sta[0] = g->sta[0] * cda + sda * temp;
    dx = pl->x - g->x;
    dy = pl->y - g->y;
    xn =  dx * g->cta[0] + dy * g->sta[0];
    yn = -dx * g->sta[0] + dy * g->cta[0];
    cn = pl->ca * g->cta[0] + pl->sa * g->sta[0];
    sn = pl->sa * g->cta[0] - pl->ca * g->sta[0];
    for (i=0; i<21; i++) {
      rx = xp[i] - xn;
      ry = yp[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - zp[i] / pry * 450;
    }
    color = g->range / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[0][0], 21);
    g->last[0] = TRUE;
  }
  else 
    g->last[0] = FALSE;
  g->ccount++;
}

void explodesalvo (g, pl)
     Genericp g;
     Genericp pl;
{
  float mrx[10], mry[10];
  float mrz[10], xmoff[10], ymoff[10], zmoff[10];
  static float gravity = 1.0;
  int i, j, k, l, color;

  if (g->last[0]) {
    gprsetdrawvalue(icol[0]);
    multiline(g->mline[0][0], 5);
  }

  if (g->attr & EXERASE || g->ecount >= 20) {
    g->attr = 0;
    return;
  }

  if (g->attr & IS_NEW) {
    g->ccount = 0;
    g->attr &= ~IS_NEW;
    for (j=0; j<5; j++) {
      g->vel[0][j] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[0][j] = - g->vel[0][j];
      g->vel[1][j] = frand() * 10.0;
      if (frand() >= 0.5)
        g->vel[1][j] = - g->vel[1][j];
      g->vel[2][j] = -7.5 - frand() * 5.0;
      g->pos[0][j] = 0.0;
      g->pos[1][j] = 0.0;
      g->pos[2][j] = 0.0;
    }
  }
  if (g->attr & IS_SEEN) {
    color = g->ccount / 4 + 8;
    if (color > 13)
      color = 13;
    gprsetdrawvalue(icol[color]);
    for (i=0; i<5; i++) {
      g->pos[0][i] = g->pos[0][i] + g->vel[0][i];
      g->pos[1][i] = g->pos[1][i] + g->vel[1][i];
      g->vel[2][i] = g->vel[2][i] + gravity;
      g->pos[2][i] = g->pos[2][i] - g->vel[2][i];
    }
    for (i=0; i<5; i++) {
      k = 2 * i;
      l = k + 1;
      xmoff[k] = g->pos[0][i] + g->x - pl->x;
      ymoff[k] = g->pos[1][i] + g->y - pl->y;
      zmoff[k] = g->pos[2][i];
      mrx[k] =  xmoff[k] * pl->ca + ymoff[k] * pl->sa;
      mry[k] = -xmoff[k] * pl->sa + ymoff[k] * pl->ca;
      mrz[k] =  zmoff[k];
      if (mry[k] < 7.5)
        mry[k] = 7.5;
      g->mline[0][k][0] = 500 + mrx[k] / mry[k] * 450;
      g->mline[0][k][1] = 260 - mrz[k] / mry[k] * 450;
      g->mline[0][l][0] = g->mline[0][k][0] + 2;
      g->mline[0][l][1] = g->mline[0][k][1] + 2;
    }
    multiline(g->mline[0][0], 5);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
  g->ccount++;
}

void drawtank (g, pl)
     Genericp g;
     Genericp pl;
{
  static float sda = 0.087156;
  static float cda = 0.996195;
  static int radxp[] = {3, 5, 5, 3, -3, -5, -5, -3};
  static int radyp[] = {0, 3, 3, 0, 0, 3, 3, 0};
  static int radzp[] = {13, 15, 19, 21, 21, 19, 15, 13};
  static int radxm[] = {5, 5};
  static int radym[] = {-40, -40};
  static int radzm[] = {10, 13};
  static int musxm[] = {3, 3, -3, -3, -3, -3, 3, 3};
  static int musym[] = {4, 60, 4, 60, 19, 60, 19, 60};
  static int muszm[] = {3, 3, 3, 3, -3, -3, -3, -3};
  static int musxp[] = {-3, 3, 3, -3};
  static int musyp[] = {60, 60, 60, 60};
  static int muszp[] = {-3, -3, 3, 3};
  static int turxp[] = {-10, -10, 10, 10, 25, 25, 10, -10,
                          -25, -25, -10, 10};
  static int turyp[] = {-45, -13, -13, -45, -50, 60, -13,
                          -13, 60, -50, -45, -45};
  static int turzp[] = {10, 10, 10, 10, -11, -20, 10, 10, -20, -11, 10, 10};
  static int basxp[] = {30, 35, 35, 30, -30, -35, -35, -30, 30, 30};
  static int basyp[] = {-53, -60, 60, 37, 37, 60, -60, -53, -53, 37};
  static int baszp[] = {-40, -10, -20, -40, -40, -20, -10, -40, -40, -40};
  static int basxm[] = {35, -35, 35, -35, -30, -30};
  static int basym[] = {-60, -60, 60, 60, -53, 37};
  static int baszm[] = {-10, -10, -20, -20, -40, -40};
  int color, i;
  float temp, csa, ssa, dx, dy, xn, yn, cn, sn;
  float poleux, poleuy, rx, ry, prx, pry;
  
  if (g->last[0]) {
    gprsetdrawvalue(icol[0]);
    polyline(g->pline[0][0], 10);
    multiline(g->mline[0][0], 3); 
    polyline(g->pline[1][0], 12);
    multiline(g->mline[1][0], 4);
    polyline(g->pline[2][0], 5);
    polyline(g->pline[3][0], 9);
    multiline(g->mline[2][0], 1);
  }
  if (g->attr & ERASE) return;
  if (g->attr & IS_SEEN) {
    color = g->range / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    temp = g->cta[0];
    g->cta[0] = g->cta[0] * cda - g->sta[0] * sda;
    g->sta[0] = g->sta[0] * cda + sda * temp;
    csa = cos(g->azm);
    ssa = sin(g->azm);
    dx = pl->x - g->x;
    dy = pl->y - g->y;
    xn =  dx * csa + dy * ssa;
    yn = -dx * ssa + dy * csa;
    cn = pl->ca * csa + pl->sa * ssa;
    sn = pl->sa * csa - ssa * pl->ca;
    poleux = radxm[0] - xn;
    poleuy = radym[0] - yn;
    for (i=0; i<2; i++) {
      rx = radxm[i] - xn;
      ry = radym[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[2][i][0] = 500 + prx / pry * 450;
      g->mline[2][i][1] = 260 - radzm[i] / pry * 450;
    }
    for (i=0; i<8; i++) {
      rx = radxp[i] * g->cta[0] - radyp[i] * g->sta[0] + poleux;
      ry = radxp[i] * g->sta[0] + radyp[i] * g->cta[0] + poleuy;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[3][i][0] = 500 + prx / pry * 450;
      g->pline[3][i][1] = 260 - radzp[i] / pry * 450;
    }
    g->pline[3][i][0] = g->pline[3][0][0];
    g->pline[3][i][1] = g->pline[3][0][1];
    for (i=0; i<8; i++) {
      rx =  musxm[i] - xn;
      ry =  musym[i] - yn;
      prx =  rx * cn + ry * sn;                     
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[1][i][0] = 500 + prx / pry * 450;
      g->mline[1][i][1] = 260 - muszm[i] / pry * 450;
    }
    for (i=0; i<4; i++) {
      rx =  musxp[i] - xn;
      ry =  musyp[i] - yn;
      prx =  rx * cn + ry * sn;                     
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[2][i][0] = 500 + prx / pry * 450;
      g->pline[2][i][1] = 260 - muszp[i] / pry * 450;
    }
    g->pline[2][i][0] = g->pline[2][0][0];
    g->pline[2][i][1] = g->pline[2][0][1];
    for (i=0; i<12; i++) {
      rx =  turxp[i] - xn;
      ry =  turyp[i] - yn;
      prx =  rx * cn + ry * sn;                     
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[1][i][0] = 500 + prx / pry * 450;
      g->pline[1][i][1] = 260 - turzp[i] / pry * 450;
    }
    for (i=0; i<6; i++) {
      rx =  basxm[i] - xn;
      ry =  basym[i] - yn;
      prx =  rx * cn + ry * sn;                     
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[0][i][0] = 500 + prx / pry * 450;
      g->mline[0][i][1] = 260 - baszm[i] / pry * 450;
    }
    for (i=0; i<10; i++) {
      rx =  basxp[i] - xn;
      ry =  basyp[i] - yn;
      prx =  rx * cn + ry * sn;                     
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - baszp[i] / pry * 450;
    }
    polyline(g->pline[0][0], 10);
    multiline(g->mline[0][0], 3);
    polyline(g->pline[1][0], 12);
    multiline(g->mline[1][0], 4);
    polyline(g->pline[2][0], 5);
    polyline(g->pline[3][0], 9);
    multiline(g->mline[2][0], 1);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
}

void drawsuper (g, pl)
     Genericp g;
     Genericp pl;
{
  float rx, ry, prx, pry;
  static int radxm[] = {22, 22};
  static int radym[] = {-52, -52};
  static int radzm[] = {-8, 28};
  static int musxm[] = {3, 3, -3, -3, 3, 3, -3, -3};
  static int musym[] = {-17, 55, -17, 55, -8, 55, -8, 55};
  static int muszm[] = {0, 0, 0, 0, -6, -6, -6, -6};
  static int musxp[] = {3, 3, -3, -3};
  static int musyp[] = {55, 55, 55, 55};
  static int muszp[] = {-6, 0, 0, -6};
  static int turxp[] = {0, 13, 11, 11, 0, -13, -11, -11, 0};
  static int turyp[] = {35, -60, -60, -25, 35, -60, -60, -25, 35};
  static int turzp[] = {-33, -6, 4, 4, -33, -6, 4, 4, -33};
  static int turxm[] = {11, -11, 11, -11};
  static int turym[] = {-60, -60, -25, -25};
  static int turzm[] = {4, 4, 4, 4};
  static int basxp[] = {15, 30, 30, 15, -15, -30, -30, -15};
  static int basyp[] = {60, -60, -60, 60, 60, -60, -60, 60};
  static int baszp[] = {-40, -40, -6, -40, -40, -40, -6, -40};
  static int basxm[] = {-30, 30, -30, 30};
  static int basym[] = {-60, -60, -60, -60};
  static int baszm[] = {-6, -6, -40, -40};
  int color, i;
  float csa, ssa, dx, dy, xn, yn, cn, sn;
  
  if (g->last[0]) {
    gprsetdrawvalue(icol[0]);
    polyline(g->pline[0][0], 8);
    multiline(g->mline[0][0], 2);
    polyline(g->pline[1][0], 9);
    multiline(g->mline[1][0], 2);
    multiline(g->mline[2][0], 4);
    polyline(g->pline[2][0], 5);
    multiline(g->mline[3][0], 1);
  }
  if (g->attr & ERASE) return;
  if (g->attr & IS_SEEN) {
    color = g->range / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    csa = cos(g->azm);
    ssa = sin(g->azm);
    dx = pl->x - g->x;
    dy = pl->y - g->y;
    xn =  dx * csa + dy * ssa;
    yn = -dx * ssa + dy * csa;
    cn = pl->ca * csa + pl->sa * ssa;
    sn = pl->sa * csa - ssa * pl->ca;
    for (i=0; i<2; i++) {
      rx =  radxm[i] - xn;
      ry =  radym[i] - yn;
      prx =  rx * cn + ry * sn;                     
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[3][i][0] = 500 + prx / pry * 450;
      g->mline[3][i][1] = 260 - radzm[i] / pry * 450;
    }
    for (i=0; i<8; i++) {
      rx =  musxm[i] - xn;
      ry =  musym[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[2][i][0] = 500 + prx / pry * 450;
      g->mline[2][i][1] = 260 - muszm[i] / pry * 450;
    }
    for (i=0; i<4; i++) {
      rx =  musxp[i] - xn;
      ry =  musyp[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[2][i][0] = 500 + prx / pry * 450;
      g->pline[2][i][1] = 260 - muszp[i] / pry * 450;
    }
    g->pline[2][i][0] = g->pline[2][0][0];
    g->pline[2][i][1] = g->pline[2][0][1];
    for (i=0; i<4; i++) {
      rx =  turxm[i] - xn;
      ry =  turym[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[1][i][0] = 500 + prx / pry * 450;
      g->mline[1][i][1] = 260 - turzm[i] / pry * 450;
    }
    for (i=0; i<9; i++) {
      rx =  turxp[i] - xn;
      ry =  turyp[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[1][i][0] = 500 + prx / pry * 450;
      g->pline[1][i][1] = 260 - turzp[i] / pry * 450;
    }
    for (i=0; i<4; i++) {
      rx =  basxm[i] - xn;
      ry =  basym[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[0][i][0] = 500 + prx / pry * 450;
      g->mline[0][i][1] = 260 - baszm[i] / pry * 450;
    }
    for (i=0; i<8; i++) {
      rx =  basxp[i] - xn;
      ry =  basyp[i] - yn;
      prx =  rx * cn + ry * sn;                     
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - baszp[i] / pry * 450;
    }
    polyline(g->pline[0][0], 8);
    multiline(g->mline[0][0], 2);
    polyline(g->pline[1][0], 9);
    multiline(g->mline[1][0], 2);
    multiline(g->mline[2][0], 4);
    polyline(g->pline[2][0], 5);
    multiline(g->mline[3][0], 1);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
}

void drawcopter (g, pl)
     Genericp g;
     Genericp pl;
{
  float rx, ry, cn, sn, xn, yn, prx, pry;
  static float cda = 0.819152;
  static float sda = 0.573576;
  static int proxp[] = {6, 6, -6, 6, -6};
  static int proyp[] = {100, 100, -100, -100, 100};
  static int prozp[] = {30, 30, 30, 30, 30};
  static int extxm[] = {0, 0, -14, -14, -14, -14, 14, 14, 14, 14};
  static int extym[] = {0, 0, -30, 40, 40, 44, -30, 40, 40, 44};
  static int extzm[] = {16, 36, -40, -40, -40, -36, -40, -40, -40, -36};
  static int talxp[] = {0, 7, 10, 0, 0, 0, 0, 0, -7, -10, 0};
  static int talyp[] = {-114, -30, -34, -116, -134, -144, -130, -114,
                          -30, -34, -116};
  static int talzp[] = {-10, -34, -14, 0, 28, 28, -10, -10, -34, -14, 0};
  static int bodxp[] = {-14, 14, 0, -14, -7, 7, 14, 26, 0, -26,
                          -10, 10, 26, 4, 0, -4, -4, 4, 4};
  static int bodyp[] = {34, 34, 60, 34, -30, -30, 34, 34, 60, 34, -34,
                          -34, 34, 20, 22, 20, -22, -22, 20};
  static int bodzp[] = {-34, -34, -14, -34, -34, -34, -34, -14, -14,
                          -14, -14, -14, -14, 16, 16, 16, 16, 16, 16};
  static int bodxm[] = {-10, -4, 10, 4, 0, 0, -14, -26, -26, -4};
  static int bodym[] = {-34, -22, -34, -22, 22, 60, 34, 34, 34, 20};
  static int bodzm[] = {-14, 16, -14, 16, 16, -14, -34, -14, -14, 16};
  int color, i;
  float temp, csa, ssa, dx, dy, x1, y1, c1, s1, prz;
  
  if (g->last[0]) {
    gprsetdrawvalue(icol[0]);
    polyline(g->pline[0][0], 6);
    multiline(g->mline[0][0], 5);
    polyline(g->pline[1][0], 11);
    polyline(g->pline[2][0], 19);
    multiline(g->mline[1][0], 5);
  }
  if (g->attr & ERASE) return;
  if (g->attr & IS_SEEN) {
    color = g->range / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    temp = g->cta[0];
    g->cta[0] = g->cta[0] * cda - g->sta[0] * sda;
    g->sta[0] = g->sta[0] * cda + sda * temp;
    csa = cos(g->azm);
    ssa = sin(g->azm);
    dx = pl->x - g->x;
    dy = pl->y - g->y;
    xn =  dx * csa + dy * ssa;
    yn = -dx * ssa + dy * csa;
    x1 =  dx * g->cta[0] + dy * g->sta[0];
    y1 = -dx * g->sta[0] + dy * g->cta[0];
    cn = pl->ca * csa + pl->sa * ssa;
    sn = pl->sa * csa - ssa * pl->ca;          
    c1 = pl->ca * g->cta[0] + pl->sa * g->sta[0];
    s1 = pl->sa * g->cta[0] - g->sta[0] * pl->ca;
    for (i=0; i<5; i++) {
      rx = proxp[i] - x1;
      ry = proyp[i] - y1;
      prx =  rx * c1 + ry * s1;
      pry = -rx * s1 + ry * c1;
      prz = prozp[i] + g->z;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - prz / pry * 450;
    }
    g->pline[0][i][0] = g->pline[0][0][0];
    g->pline[0][i][1] = g->pline[0][0][1];
    for (i=0; i<10; i++) {
      rx = extxm[i] - xn;
      ry = extym[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      prz = extzm[i] + g->z;
      if (pry < 10.0)
        pry = 10.0;
      g->mline[0][i][0] = 500 + prx / pry * 450;
      g->mline[0][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<11; i++) {
      rx = talxp[i] - xn;
      ry = talyp[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      prz = talzp[i] + g->z;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[1][i][0] = 500 + prx / pry * 450;
      g->pline[1][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<19; i++) {
      rx = bodxp[i] - xn;
      ry = bodyp[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      prz = bodzp[i] + g->z;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[2][i][0] = 500 + prx / pry * 450;
      g->pline[2][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<10; i++)
      {
        rx = bodxm[i] - xn;
        ry = bodym[i] - yn;
        prx =  rx * cn + ry * sn;
        pry = -rx * sn + ry * cn;
        prz = bodzm[i] + g->z;
        if (pry < 10.0)
          pry = 10.0;
        g->mline[1][i][0] = 500 + prx / pry * 450;
        g->mline[1][i][1] = 260 - prz / pry * 450;
      }
    polyline(g->pline[0][0], 6);
    multiline(g->mline[0][0], 5);
    polyline(g->pline[1][0], 11);
    polyline(g->pline[2][0], 19);
    multiline(g->mline[1][0], 5);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
}

void drawmissile(g, pl)
     Genericp g;
     Genericp pl;
{
  float rx, ry, prx, pry, prz;
  static int capx[] = {15, 25, 0, 15, -15, 0, 15, -15, 0, -25, -15};
  static int capy[] = {-30, -30, -45, -30, -30, -45, -30, -30, -45,
                         -30, -30};
  static int capz [] = {-25, 0, 0, -25, -25, 0, 25, 25, 0, 0, 25};
  static int conx[] = {15, 0, 25, 15, 0, -15, -25, 0, -15};
  static int cony[] = {-30, 50, -30, -30, 50, -30, -30, 50, -30};
  static int conz[] = {-25, 0, 0, 25, 0, -25, 0, 0, 25};
  static int finx[] = {13, 15, 23, 23};
  static int finy[] = {-17, -30, -38, 0};
  static int finz[] = {-21, -25, -40, -40};
  int color, i;
  float csa, ssa, dx, dy, xn, yn, cn, sn, rx1, ry1, rx2, ry2;
  float prx1, pry1, prx2, pry2;
  
  if (g->last[0]) {
    gprsetdrawvalue(0);
    polyline(g->pline[0][0], 11);
    polyline(g->pline[1][0], 9);
    polyline(g->pline[2][0], 5);
    polyline(g->pline[3][0], 5);
  }
  if (g->attr & ERASE) return;
  if (g->attr & IS_SEEN) {
    color = g->range / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    csa = cos(g->azm);
    ssa = sin(g->azm);
    dx = pl->x - g->x;
    dy = pl->y - g->y;
    xn =  dx * csa + dy * ssa;
    yn = -dx * ssa + dy * csa;
    cn = pl->ca * csa + pl->sa * ssa;
    sn = pl->sa * csa - ssa * pl->ca;
    for (i=0; i<11; i++) {
      rx =  capx[i] - xn;
      ry =  capy[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      prz =  capz[i] + g->z;
      if (pry < 10.0) pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<9; i++) {
      rx =  conx[i] - xn;
      ry =  cony[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      prz =  conz[i] + g->z;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[1][i][0] = 500 + prx / pry * 450;
      g->pline[1][i][1] = 260 - prz / pry * 450;
    }
    for (i=0; i<4; i++) {
      rx1 =  finx[i] - xn;
      ry1 =  finy[i] - yn;
      rx2 = -finx[i] - xn;
      ry2 =  finy[i] - yn;
      prx1 =  rx1 * cn + ry1 * sn;
      pry1 = -rx1 * sn + ry1 * cn;
      prx2 =  rx2 * cn + ry2 * sn;                    
      pry2 = -rx2 * sn + ry2 * cn;
      prz =  finz[i] + g->z;
      if (pry1 < 10.0)
        pry1 = 10.0;
      if (pry2 < 10.0)
        pry2 = 10.0;
      g->pline[2][i][0] = 500 + prx1 / pry1 * 450;
      g->pline[2][i][1] = 260 - prz / pry1 * 450;
      g->pline[3][i][0] = 500 + prx2 / pry2 * 450;
      g->pline[3][i][1] = 260 - prz / pry2 * 450;
    }
    g->pline[2][i][0] = g->pline[2][0][0];
    g->pline[2][i][1] = g->pline[2][0][1];
    g->pline[3][i][0] = g->pline[3][0][0];
    g->pline[3][i][1] = g->pline[3][0][1];
    polyline(g->pline[0][0], 11);
    polyline(g->pline[1][0], 9);
    polyline(g->pline[2][0], 5);
    polyline(g->pline[3][0], 5);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
}

void drawlander (g, pl)
     Genericp g;
     Genericp pl;
{
  float temp, rx, ry, prx, pry;
  static int xp[] = {0, 80, 40, -40, -80, 0, 0, 0, 0, 0, 0, -57, -28,
                       28, 57, 0, 57, 28, -28, -57, 0};
  static int yp[] = {0, 0, 0, 0, 0, 0, 80, 40, -40, -80, 0, -57, -28,
                       28, 57, 0, -57, -28, 28, 57, 0};
  static int zp[] = {20, -20, -40, -40, -20, 20, -20, -40, -40, -20,
                       20, -20, -40, -40, -20, 20, -20, -40, -40, -20, 20};
  static float sda = 0.087156;
  static float cda = 0.996195;
  float dx, dy, xn, cn, sn, yn;
  int i, color;
  
  if (g->last[0]) {
    gprsetdrawvalue(icol[0]);
    polyline(g->pline[0][0], 21);
  }
  if (g->attr & ERASE) return;
  if (g->attr & IS_SEEN) {
    temp = g->cta[0];
    g->cta[0] = g->cta[0] * cda - g->sta[0] * sda;
    g->sta[0] = g->sta[0] * cda + sda * temp;
    dx = pl->x - g->x;
    dy = pl->y - g->y;
    xn =  dx * g->cta[0] + dy * g->sta[0];
    yn = -dx * g->sta[0] + dy * g->cta[0];
    cn = pl->ca * g->cta[0] + pl->sa * g->sta[0];
    sn = pl->sa * g->cta[0] - pl->ca * g->sta[0];
    for (i=0; i<21; i++) {
      rx = xp[i] - xn;
      ry = yp[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 10.0)
        pry = 10.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - zp[i] / pry * 450;
    }
    color = g->range / 300 + 2;
    if (color > 7)
      color = 7;
    gprsetdrawvalue(icol[color]);
    polyline(g->pline[0][0], 21);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
}

void drawsalvo(g, pl)
     Genericp g;
     Genericp pl;
{
  float prx, pry, csa, ssa, rx, ry;
  static int xp[] = {0, 8, 0, 8, 0, 0, -8, 0, 0, -8};
  static int yp[] = {-10, -10, -10, -10, 10, -10, -10, 10, -10, -10};
  static int zp[] = {-8, 0, 8, 0, 0, 8, 0, 0, -8, 0};
  int color, i;
  float dx, dy, xn, yn, cn, sn;

  if (g->last[0]) {
    gprsetdrawvalue(icol[0]);
    polyline(g->pline[0][0], 10);
  }
  if (g->attr & ERASE) return;
  if (g->attr & IS_SEEN) {
    color = g->range / 300 + 8;
    if (color > 13)
      color = 13;
    gprsetdrawvalue(icol[color]);
    csa = cos(g->azm);
    ssa = sin(g->azm);
    dx = pl->x - g->x;
    dy = pl->y - g->y;
    xn =  dx * csa + dy * ssa;
    yn = -dx * ssa + dy * csa;
    cn = pl->ca * csa + pl->sa * ssa;
    sn = pl->sa * csa - ssa * pl->ca;
    for (i=0; i<10; i++) {
      rx =  xp[i] - xn;
      ry =  yp[i] - yn;
      prx =  rx * cn + ry * sn;
      pry = -rx * sn + ry * cn;
      if (pry < 7.5)
        pry = 7.5;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 + zp[i] / pry * 450;
    }
    polyline(g->pline[0][0], 10);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
}

void drawpyramid(g, pl)
     Genericp g;
     Genericp pl;
{
  float prx, pry, xpoff, ypoff;
  static int xp[] = {-40, 40, 40, 40, 0, -40, -40, 0, 40, -40};
  static int yp[] = {40, 40, -40, 40, 0, 40, -40, 0, -40, -40};
  static int zp[] = {-40, -40, -40, -40, 40, -40, -40, 40, -40, -40};
  int color, i;

  if (g->last[0]) {
    gprsetdrawvalue(0);
    polyline(g->pline[0][0], 10);
    gprsetdrawvalue(1);
  }
  if (g->attr & ERASE) return;
  if (g->attr & IS_SEEN) {
    color = g->range / 300 + 8;
    if (color > 13)
      color = 13;
    gprsetdrawvalue(icol[color]);
    for (i=0; i<10; i++) {
      xpoff = xp[i] + g->x - pl->x;
      ypoff = yp[i] + g->y - pl->y;
      prx =  xpoff * pl->ca + ypoff * pl->sa;                     
      pry = -xpoff * pl->sa + ypoff * pl->ca;
      if (pry < 7.5)
        pry = 7.5;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - zp[i] / pry * 450;
    }
    polyline(g->pline[0][0], 10);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
}

void drawcube(g, pl)
     Genericp g;
     Genericp pl;
{
  float mrx, mry, prx, pry, xpoff, ypoff, xmoff, ymoff;
  static int xp[] = {-40, -40, 40, 40, -40, -40, 40, 40, -40, -40};
  static int yp[] = {40, 40, 40, 40, 40, -40, -40, -40, -40, -40};
  static int zp[] = {-40, 40, 40, -40, -40, -40, -40, 40, 40, -40};
  static int xm[] = {-40, -40, 40, 40, 40, 40};
  static int ym[] = {-40, 40, -40, 40, -40, 40};
  static int zm[] = { 40, 40, 40, 40, -40, -40};
  int i, color;

  if (g->last[0]) {
    gprsetdrawvalue(icol[0]);
    polyline(g->pline[0][0], 10);
    multiline(g->mline[0][0], 3);
  }
  if (g->attr & ERASE) return;
  if (g->attr & IS_SEEN) {
    color = g->range / 300 + 8;
    if (color > 13)
      color = 13;
    gprsetdrawvalue(icol[color]);
    for (i=0; i<10; i++) {
      xpoff = xp[i] + g->x - pl->x;
      ypoff = yp[i] + g->y - pl->y;
      prx =  xpoff * pl->ca + ypoff * pl->sa;
      pry = -xpoff * pl->sa + ypoff * pl->ca;
      if (pry < 5.0)
        pry = 5.0;
      g->pline[0][i][0] = 500 + prx / pry * 450;
      g->pline[0][i][1] = 260 - zp[i] / pry * 450;
    }
    for (i=0; i<6; i++) {
      xmoff = xm[i] + g->x - pl->x;
      ymoff = ym[i] + g->y - pl->y;
      mrx =  xmoff * pl->ca + ymoff * pl->sa;
      mry = -xmoff * pl->sa + ymoff * pl->ca;
      if (mry < 5.0)
        mry = 5.0;
      g->mline[0][i][0] = 500 + mrx / mry * 450;
      g->mline[0][i][1] = 260 - zm[i] / mry * 450;
    }
    polyline(g->pline[0][0], 10);
    multiline(g->mline[0][0], 3);
    g->last[0] = TRUE;
  }
  else
    g->last[0] = FALSE;
}
