home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume6 / gb / patch1 / rst.c < prev    next >
C/C++ Source or Header  |  1989-07-06  |  6KB  |  284 lines

  1.  
  2. /*
  3.  * Galactic Bloodshed (Robert Chansky, smq@b)
  4.  *  ship -- report -- stock -- tactical -- stuff on ship
  5.  */
  6.  
  7. #define REPORT    0
  8. #define STOCK    1
  9. #define TACTICAL 2
  10. #define SHIP    3
  11. #define OBJECT    4
  12.  
  13. #include <math.h>
  14. #include "vars.h"
  15. #include "ships.h"
  16. extern char Shipltrs[];
  17. extern char *prin_ship_dest();
  18. extern int God;
  19. extern int Ignore_filelocks;
  20. static bool Object,Ship,Stock,Report,Tactical,first;
  21.  
  22. struct reportdata {
  23.     shiptype *s;
  24.     short n;
  25.     float x,y;
  26. };
  27.  
  28. int Num_ships;
  29.  
  30. rst(APcount, argn,args,Rst)
  31. int APcount;
  32. int argn;
  33. char args[MAXARGS][COMMANDSIZE];
  34. int Rst;
  35. {
  36.  int shdata,shipno;
  37.  reg int i;
  38.  struct reportdata sh[MAXTOTALSHIPS];
  39.  
  40.  Num_ships = 0;
  41.  first = 1;
  42.  switch (Rst) {
  43.     case REPORT:    Report = 1;
  44.             Object = Stock = Ship = Tactical = 0;
  45.             break;
  46.     case STOCK:    Stock = 1;
  47.             Object = Report = Ship = Tactical = 0;
  48.             break;
  49.     case TACTICAL:    Tactical = 1;
  50.             Object = Report = Ship = Stock = 0;
  51.             break;
  52.     case SHIP:    Ship = Report = Stock = Tactical = 1;
  53.             Object = 0;
  54.             break;
  55.     case OBJECT:    Object = Report = Stock = Tactical = 1;
  56.             Ship = 0;
  57.             break;
  58.  }
  59.  
  60.  if (argn==2) {
  61.    sscanf(args[1] + (*args[1]=='#' ? 1 : 0),"%d",&shipno);
  62.    openshdata(&shdata);
  63.    Getrship(shdata,sh, shipno, 0.0, 0.0);
  64.    close(shdata);
  65.    ship_report(sh,0);        /* first ship report */
  66.  
  67.  } else
  68.  
  69.   switch (Dir.level) {
  70.    case LEVEL_UNIV:
  71.       if (Sdata.numships) {
  72.       openshdata(&shdata);
  73.       for (i=0; i<MAXUSHIPS; i++) {
  74.         if (Sdata.shipnums[i])
  75.           Getrship(shdata,sh, Sdata.shipnums[i],0.0, 0.0);
  76.       }
  77.       close(shdata);
  78.       }
  79.       for (i=0; i<Sdata.numstars; i++)
  80.         star_getrships(sh,i);
  81.       for (i=0; i<Num_ships; i++)
  82.         ship_report(sh,i);
  83.       break;
  84.    case LEVEL_STAR:
  85.       star_getrships(sh,Dir.snum);
  86.       for (i=0; i<Num_ships; i++)
  87.         ship_report(sh,i);
  88.       break;
  89.    case LEVEL_PLAN:
  90.       plan_getrships(sh,Stars[Dir.snum]->planetpos[Dir.pnum],Stars[Dir.snum]->xpos,Stars[Dir.snum]->ypos);
  91.       for (i=0; i<Num_ships; i++)
  92.         ship_report(sh,i);
  93.       break;
  94.    case LEVEL_SHIP:
  95.       openshdata(&shdata);
  96.       Getrship(shdata,sh, Dir.shipno,0.0,0.0);
  97.       close(shdata);
  98.       ship_report(sh,0);        /* first ship report */
  99.       break;
  100.   }
  101.  
  102.   Free_shiplist(sh);
  103.  
  104. }
  105.  
  106.  
  107. ship_report(sh,indx)
  108. struct reportdata sh[];
  109. int indx;
  110. {
  111.  shiptype *s;
  112.  int shipno;
  113.  reg int i;
  114.  placetype where;
  115.  char orb[PLACENAMESIZE];
  116.  float Dist;
  117.  
  118.     /* last ship gotten from disk */
  119.   s = sh[indx].s;
  120.   shipno = sh[indx].n;
  121.  
  122.  
  123.     /* a launched canister doesn't show up */
  124.   if ( !(s->type==OTYPE_CANIST && !s->is_docked) ) {
  125.  
  126.  
  127.    if (Stock) {
  128.     if (first) {
  129.       printf("  #   mass res  ^res  dest ^dest   fuel ^fuel  crew ^crew dock\n");
  130.       if (!Ship && !Object)
  131.           first=0;
  132.     }
  133.     /*if (is_object(s) == Object)*/
  134.      if (s->owner == Playernum || God) {
  135.       printf("%3d %c%5.1f%4u%6d%6u%6d%7.1f%6d%6u%6d%5s",
  136.     shipno, Shipltrs[s->type], s->mass,
  137.     s->resource, Shipdata[s->type][ABIL_CARGO],
  138.     s->destruct, Shipdata[s->type][ABIL_DESTCAP],
  139.     s->fuel, Shipdata[s->type][ABIL_FUELCAP],
  140.     s->popn, Shipdata[s->type][ABIL_MAXCREW],
  141.     (s->is_docked) ? ((s->whatdest==LEVEL_PLAN) ? "land" : "dock") :"    ");
  142.       if (s->type==OTYPE_VN) 
  143.     printf(" * %d",s->orders.object.number);
  144.       if (s->rad)
  145.     printf(" INACTIVE(%d)",s->rad);
  146.       putchr('\n');
  147.  
  148.     }
  149.    }
  150.    if (Report) {
  151.          if (first) {
  152.          printf("  #   own dam dest  fuel land               orbits           destination\n");
  153.          if (!Ship && !Object)
  154.               first=0;
  155.      }
  156.  
  157.     if (s->owner == Playernum || God) {
  158.      /*if (is_object(s) == Object) */
  159.        printf("%3d %c%4u%4u%5u%6.1f%5s %20s %21s",
  160.         shipno, Shipltrs[s->type],
  161.         s->owner, s->damage, s->destruct, s->fuel, 
  162.         (s->is_docked) ? ( (s->whatdest==LEVEL_SHIP) ? "dock" 
  163.             : "land") : "    ",
  164.         prin_ship_orbits(s), prin_ship_dest(s) );
  165.          if (s->type==OTYPE_VN) printf("* %d",s->orders.object.number);
  166.       if (s->rad)
  167.     printf(" INACTIVE(%d)",s->rad);
  168.          putchr('\n');
  169.  
  170.     }
  171.    }
  172.     /* objects dont have a tac display */
  173.    if (Tactical) {
  174.     printf("  # typ dest  fuel dam    x,y abs     x,y rel    orbits\n");
  175.      where.level = s->whatorbits;
  176.      where.snum = s->storbits;
  177.      where.pnum = s->pnumorbits;
  178.     sprintf(orb, "%.30s", Dispplace(&where));
  179.     printf("%3d  %c%6u%6.1f%4u%7.0f,%-7.0f%7.0f,%-7.0%10s",
  180.         shipno, Shipltrs[s->type], s->destruct,
  181.         s->fuel, s->damage, 
  182.         s->xpos, s->ypos, s->xpos-sh[indx].x, s->ypos-sh[indx].y, orb );
  183.     if (s->type == OTYPE_VN)
  184.         printf(" * %d", s->orders.object.number);
  185.         if (s->rad)
  186.         printf(" INACTIVE(%d)",s->rad);
  187.     putchr('\n');
  188.  
  189.     if (!s->rad && Shipdata[s->type][ABIL_GUNS]) {
  190.       printf("Tac display:  # own typ   rng  %dam\n");
  191.       for (i=0; i<Num_ships; i++)
  192.         if (sh[i].s->owner != Playernum && sh[i].n!=shipno &&
  193.             (Dist = sqrt(Distsq(s->xpos, s->ypos, sh[i].s->xpos,
  194.                 sh[i].s->ypos))) < SYSTEMSIZE) {
  195.            printf("%15d%4d%6.0f%6.0f",
  196.             sh[i].n, sh[i].s->owner, Shipltrs[sh[i].s->type], 
  197.             Dist, 0.0 );
  198.            if (sh[i].s->type==OTYPE_VN)
  199.             printf(" * %d", sh[i].s->orders.object.number);
  200.            putchr('\n');
  201.         }
  202.     }
  203.    }
  204.  
  205.  
  206.   }
  207.  
  208. }
  209.  
  210.  
  211.  
  212. plan_getrships(sh,filepos,starx,stary)
  213. struct reportdata sh[];
  214. int filepos;
  215. float starx,stary;
  216. {
  217.  register int i;
  218.  planettype *p;
  219.  int shdata,pdata;
  220.  
  221.  openpdata(&pdata);
  222.  getplanet(pdata, &p,filepos);
  223.  close(pdata);
  224.  
  225.  if (p->info[Playernum-1].explored) {
  226.  
  227.    openshdata(&shdata);
  228.      for (i=0; i<MAXPSHIPS; i++)
  229.          if (p->shipnums[i])
  230.         Getrship(shdata, sh, p->shipnums[i], starx, stary);
  231.    close(shdata);
  232.  }
  233.  free(p);
  234. }
  235.  
  236.  
  237. star_getrships(sh,snum)
  238. struct reportdata sh[];
  239. int snum;
  240. {
  241.  register int i;
  242.  int shdata;
  243.  
  244.  if (isset(Stars[snum]->inhabited, Playernum)) {
  245.    openshdata(&shdata);
  246.    for (i=0; i<MAXSSHIPS; i++)
  247.      if (Stars[snum]->shipnums[i])
  248.     Getrship(shdata, sh, Stars[snum]->shipnums[i], Stars[snum]->xpos, 
  249.         Stars[snum]->ypos);
  250.    close(shdata);
  251.    for (i=0; i<Stars[snum]->numplanets; i++)
  252.      plan_getrships(sh,Stars[snum]->planetpos[i],Stars[snum]->xpos,Stars[snum]->ypos);
  253.  }
  254. }
  255.  
  256.  
  257. /* get a ship from the disk and add it to the ship list we're maintaining. */
  258. Getrship(shdata,sh, shipno,xoff, yoff)
  259. int shdata,shipno;
  260. struct reportdata sh[];
  261. float xoff, yoff;
  262. {
  263. int noerr;
  264.  
  265.    Ignore_filelocks = 1;
  266.     noerr = getship(shdata,&sh[Num_ships].s,shipno);
  267.    Ignore_filelocks = 0;
  268.    sh[Num_ships].n = shipno;
  269.    sh[Num_ships].x = xoff;
  270.    sh[Num_ships].y = yoff;
  271.   if (noerr)
  272.     Num_ships++;
  273. }
  274.  
  275.  
  276. Free_shiplist(sh)
  277. struct reportdata sh[];
  278. {
  279.  reg int i;
  280.  
  281.  for (i=0; i<Num_ships; i++)
  282.     free(sh[i].s);
  283. }
  284.