home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / bbs / starbatt / st1b.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-03  |  28.1 KB  |  998 lines

  1. /* Star Trek IG style
  2. by Kevin Moody
  3. */
  4.  
  5. #include "st1b.h"
  6.  
  7. main(argc, argv)
  8. int argc;
  9. char *argv[];
  10. {
  11.     int i; char c;
  12.     stp = string;
  13.     calltype = 1;
  14.     loc = 0;
  15.     for(i=1; i<argc; i++) {
  16.         if(!strcmp(argv[i], "LOCAL"))
  17.         {
  18.             calltype=0;
  19.             loc=1;
  20.         } 
  21.         if(!strcmp(argv[i], "local"))
  22.         {
  23.             calltype=0;
  24.             loc=1;
  25.         } }
  26.  
  27.     foremout("G#I>0:s>0:k>0:C>2,0:B>0,190,640,200,0:S>0,0,0,0:S>1,0,0,0:S>2,0,0,0:S>3,0,0,0:C>2,2:B>20,20,620,32,0:C>2,1:B>20,32,620,44,0:G>1,3,20,20,620,44:&>44,150,24,0,G,4,2,3,20,x:C>2,0:H>0:B>20,176,620,188,0:C>2,3:\r ");
  28.     foremout("G#B>20,20,300,103,0:L>35,32,41,26:D>47,32:D>32,28:D>50,28:D>35,32:L>38,29,45,29:G>1,3,32,26,50,32:&>32,220,46,0,G,4,2,3,x,26:G>1,3,32,26,280,32:&>26,80,15,0,G,4,2,3,32,x:G>1,3,32,26,239,32:\r ");
  29.     foremout("G#&>34,76,15,0,G,4,2,3,55,x:G>1,3,20,20,620,200:s>0:S>1,6,6,6:S>2,6,0,0:S>3,0,0,4:E>0,20,0:&>200,20,1,0,G,4,2,3,20,x:E>0,10,0:b>8:W>250,12,STAR BATTLE@\r ");
  30.     foremout("G#W>230,195,By Kevin Moody@C>2,0:b>17:s>0:B>0,190,640,199,0:\r ");
  31.     foremout("G#b>22,12:&>1,1,1,0,n,60,12,1,15,55,220,0:12,1,15,60,80,1:12,1,15,65,255,1:12,1,15,64,100,1:12,1,15,60,60,1:12,1,15,57,60,1:12,1,15,62,60,1:12,1,15,67,255,1:12,1,15,67,60,1:12,1,15,71,300,1:\r ");
  32.  
  33.     load();
  34.     planet();
  35.     
  36.     foremout("G#I>0:s>0:k>0:S>0,7,7,7:S>2,0,0,4:S>3,4,4,7:C>2,2:A>2,8,1:B>0,0,639,199,0:C>2,3:A>2,7,1:B>5,4,275,134,1:C>2,2:A>2,8,1:B>12,8,267,130,1:C>2,3:A>2,6,1:B>284,4,634,138,0:C>2,1:A>2,8,1:B>308,22,616,132,1:\r ");
  37.      foremout("G#X>4,47,1,1,638,198,1,?:A>2,5,1:A>2,5,1:O>300,15,7:O>621,15,7:C>1,0:&>352,572,44,0,L,4,x,22,x,132:&>44,110,22,0,L,4,308,x,615,x:C>2,1:A>2,4,1:B>4,140,636,197,1:E>1,10,0:M>2:C>3,1:W>393,18,Ship View Screen@\r ");
  38.     foremout("G#M>1:C>2,0:A>2,4,1:B>17,173,623,194,1:E>0,10,0:M>2:C>3,3:W>95,21,Ship Status@E>4,9,0:C>3,0:W>25,38,STRUCTURE@W>25,46,PHASORS@W>25,54,TORPEDOS@W>25,62,ENGINES@W>25,70,CLASS@W>25,78,SCORE@W>25,86,CRYSTALS@\r ");
  39.     foremout("G#W>25,118,CAPT.@M>1:C>2,1:A>2,6,1:B>18,144,623,169,1:C>2,3:A>2,8,1:B>32,147,123,167,1:B>149,147,240,167,1:B>266,147,350,167,1:B>383,147,474,167,1:B>500,147,591,167,1:\r ");
  40.     foremout("G#M>2:C>3,1:A>2,6,1:W>52,160,Cruise@W>168,160,Warp@W>285,160,Scan@W>402,160,Quit@W>519,160,Help@M>1:C>2,1:A>1,1,1:O>209,91,33:E>4,9,0:M>2:C>3,0:W>87,95,Turns Left@\r ");
  41.     foremout("G#X>4,0,32,147,123,167,1,C:X>4,1,149,147,240,167,1,W:X>4,2,266,147,350,167,1,S:X>4,3,383,147,474,167,1,Q:X>4,4,500,147,591,167,1,H:p>5,22:\r ");
  42.     
  43.     draw(p->px, YOU);
  44.     update();
  45.  
  46. while (zap != 1)  {
  47.     zap = 0; holy = 1;
  48.     foremout("G#T>1,6,4:b>7:<>1,2,1:\r ");    
  49.  
  50.     c = foremgetc();       /* Respond to mouse button */
  51.     if(c=='C')               /* Cruise */
  52.       {
  53.     foremout("G#X>4,9999:S>3,6,4,1:S>2,0,4,3:C>2,3:A>2,8,1:B>32,147,123,167,1:B>149,147,240,167,1:B>266,147,350,167,1:B>383,147,474,167,1:B>500,147,591,167,1:\r ");
  54.     foremout("G#X>4,47,1,1,638,198,1,?:M>2:C>3,1:A>2,6,1:W>52,160,Up@W>168,160,Down@W>285,160,Left@W>402,160,Right@W>519,160,Bridge@\r ");
  55.     foremout("G#X>4,0,32,147,123,167,1,U:X>4,1,149,147,240,167,1,D:X>4,2,266,147,350,167,1,L:X>4,3,383,147,474,167,1,R:X>4,4,500,147,591,167,1,B:\r ");     
  56.       cruise();
  57.       }
  58.     if(c=='W') warp();
  59.     if(c=='S') scan();
  60.     if(c=='Q') zap=1;
  61.     if(c=='?') zap=2;
  62.  
  63.     if(zap==0)  {                   /* define and draw main buttons  */
  64.         foremout("G#X>4,9999:S>2,0,0,4:S>3,4,4,7:X>4,47,1,1,638,198,1,?:C>2,1:A>2,8,1:B>308,22,616,132,1:C>1,0:&>352,572,44,0,L,4,x,22,x,132:&>44,110,22,0,L,4,308,x,615,x:\r ");
  65.         foremout("G#C>2,3:A>2,8,1:B>32,147,123,167,1:B>149,147,240,167,1:B>266,147,350,167,1:B>383,147,474,167,1:B>500,147,591,167,1:\r ");
  66.         foremout("G#X>4,47,1,1,638,198,1,?:M>2:C>3,1:A>2,6,1:W>52,160,Cruise@W>168,160,Warp@W>285,160,Scan@W>402,160,Quit@W>519,160,Help@\r ");
  67.         foremout("G#X>4,0,32,147,123,167,1,C:X>4,1,149,147,240,167,1,W:X>4,2,266,147,350,167,1,S:X>4,3,383,147,474,167,1,Q:X>4,4,500,147,591,167,1,H:\r ");     
  68.         draw(p->px, YOU);
  69.         update();  }
  70.     }         /* Player chose to quit game  */
  71.     save();
  72.     foremout("G#:I>0:s>0:S>2,7,0,0:S>3,0,7,0:k>1:\r ");
  73.     Pterm(0);
  74. }
  75. cruise()
  76. {
  77.     int x;
  78.     char c;
  79.  
  80.   /* draw and define cruise buttons - arrows */
  81. do{  update();
  82.     foremout("G#<>1,2,1:\r ");
  83.     
  84.      c=foremgetc();
  85.     old = x = p->px;
  86.      if(c=='U')        /* move up 1 space */
  87.           {
  88.     if(x<7) x += 28;
  89.     else 
  90.     x -= 7; 
  91.           }
  92.     if(c=='D')
  93.           {
  94.           if(x>27) x -= 28;
  95.     else
  96.     x += 7;
  97.           }
  98.     if(c=='L')
  99.           {
  100.     t = x % 7;
  101.           if(t==0) x += 6;
  102.     else
  103.     x -= 1; 
  104.           }
  105.     if(c=='R')
  106.           {
  107.     t = (x+1) % 7;
  108.     if(t==0) x -= 6;
  109.     else
  110.     x += 1; 
  111.           }
  112.     if(c=='B')  break;
  113.     if(c=='?')    ;
  114.     if(p->energy==0) rebuild(ENGINES);
  115.     if(p->energy > 0) {
  116.     if(c!='?') foremout("G#b>12:\r ");
  117.     draw(old, NONE);
  118.     draw(x, YOU);
  119.     p->px = x;
  120.     if(x!=old) { turn(); p->energy -= 10; }
  121.     if(p->energy <= 0) p->energy=0;
  122.     }
  123.      }while();
  124.     nocry = 0;
  125. }
  126.  
  127. warp()  
  128. {
  129.  
  130. int dep, rer=0, where;
  131.     foremout("G#M>1:C>2,0:A>2,4,1:B>17,173,623,194,1:\r ");
  132. do{    
  133.     foremout("G#p>5,22:\r Warp to Sector (1 - 35): (0=Exit) ");
  134.     foremin(stp);
  135.     sscanf(string,"%d", &where);
  136.     if(where==0) break;
  137.     if((where < 0) || (where > 35)) continue;
  138.     if(p->energy==0) rebuild(ENGINES);
  139.     if(p->energy > 0) {
  140.     foremout("G#b>5:\r ");
  141.     old = p->px;
  142.     p->px = where - 1;
  143.     draw(old, NONE);
  144.     draw(p->px,YOU);
  145.     if(p->px!=old) p->energy -= 30;
  146.     nocry = 0;
  147.     update();
  148.     }
  149.     break;
  150.   }while();
  151. }
  152.  
  153. draw(m,n)
  154. int m, n;
  155. {    int x;
  156.     static char eex[10], eey[10], bigy[30];
  157.     for (x=0;x<30;x++) bigy[x]='\0';
  158.     grid(m);
  159.     itoa(eex, a); itoa(eey, b);
  160.     foremout("G#M>1:H>0:A>1,1,1:\r ");
  161.     switch(n) {
  162.     case MOON:
  163.     foremout("G#C>2,0:\r ");
  164.     break;
  165.     case OTHER:
  166.     foremout("G#H>1:C>2,3:\r ");
  167.     break;
  168.     case ALIEN:
  169.     foremout("G#H>1:C>2,2:\r ");    
  170.     break;
  171.     case YOU:
  172.     foremout("G#H>1:C>2,0:\r ");    
  173.     break;
  174.     case NONE:
  175.     foremout("G#C>2,1:\r ");    
  176.     break;
  177.     }
  178.     strcpy(bigy,"G#O>");
  179.     strcat(bigy,eex);
  180.     strcat(bigy,",");
  181.     strcat(bigy,eey);
  182.     strcat(bigy,",12:\r ");
  183.     foremout(bigy);       /* radius of old circle  */
  184. }
  185. scan()
  186. {
  187.     int planet = 0, x, hm=0;
  188. char i;
  189.     setscan();
  190. do{    combat();
  191.     update();
  192.     foremout("G#<>1,2,1:\r ");
  193.  
  194.     i=foremgetc();
  195.     if(i=='O')        /* orbit nearby planet  */
  196.           {
  197.     for(x=0; x<35; x++)  
  198.     if(brd[p->px][x] == MOON) planet = TRUE; 
  199.     if(planet == FALSE) {
  200.     foremout("G#p>5,22:\r No Planet in this sector...."); 
  201.     foremout("G#t>1:\r "); }
  202.     else  {orbit(); setscan(); }
  203.         }
  204.     if(i=='A')  {
  205.         attack(); 
  206.         setscan(); 
  207.         }
  208.     if(i=='B')  break;   /* Bridge */
  209.     if(i=='C')             /* communicate  */
  210.           {
  211.     for(x=0; x<35; x++)  
  212.     if(brd[(p->px)][x] == ALIEN) {
  213.      foremout("G#p>5,22:\r Aliens attacking...Communications aborted! G#t>1:\r ");
  214.     combat(); hm=1; break; }
  215.     if(!hm) showp();
  216.     }
  217.     if(i=='?')  ;
  218.     foremout("G#p>5,22:\r ");
  219.     }while();
  220. }
  221. orbit()
  222. {
  223.     int  cry, x, fel, treaty=0,  recv, barb, mu, mine=0;
  224.     static char eex[10], c, st[2], bigy[10];
  225.     
  226.     for (x=0; x< MAX; x++)  {
  227.         if(brd[(p->px)][x] == ALIEN)  {
  228.     foremout("G#p>5,22:\r Aliens attacking...Planet Orbiting is aborted!");
  229.     foremout("G#t>1:p>5,22:\r ");
  230.         return;  } }
  231.     fel = rnd(10);
  232.     cry = rnd(200) + 1000*(pl[p->px].class) + rnd(5);
  233.     mu = pl[p->px].align;
  234.     /* Erase sectors with black fill box  and draw increasing fill circle*/
  235.         foremout("G#X>4,9999:S>2,4,0,0:C>2,1:A>2,8,1:B>308,22,616,132,1:C>2,3:A>2,8,1:B>32,147,123,167,1:B>149,147,240,167,1:B>266,147,350,167,1:B>383,147,474,167,1:B>500,147,591,167,1:\r ");
  236.         foremout("G#X>4,47,1,1,638,198,1,?:M>2:C>3,1:A>2,6,1:W>52,160,Treaty@W>168,160,Comm@W>285,160,Mine@W>402,160,Bridge@\r ");
  237.         barb = rnd(4); if(barb==0) barb=2; if(barb==1) barb=3; itoa(st, barb);
  238.         strcpy(bigy, "G#C>2,"); strcat(bigy,st); strcat(bigy,":\r "); foremout(bigy);
  239.         foremout("G#&>3,120,12,0,O,3,462,77,x:X>4,0,32,147,123,167,1,T:X>4,1,149,147,240,167,1,C:X>4,2,266,147,350,167,1,M:X>4,3,383,147,474,167,1,B:\r ");     
  240.     p->energy -= 5;
  241.     if(p->energy <= 0) p->energy=0;
  242.  
  243. do{        update();
  244.     foremout("G#p>5,22:<>1,2,1:\r ");
  245.      c=foremgetc();
  246.      if(c=='T')        /* Make peace treaty with planet */
  247.           {
  248.     treaty = 1; mine =1;
  249.     turn();
  250.     p->energy -= 5;
  251.     if(p->energy <= 0) p->energy=0;
  252.     foremout("G#p>5,22:\r Peace Treaty is acknowledged and accepted");
  253.     foremout("G#t>1:\r ");
  254.           }
  255.     if(c=='C')        /* Comm link to get market stats  */
  256.           {
  257.     if( ( mu==2 || ( mu==1 && fel<6 ) ) && !treaty ) {
  258.     foremout("G#p>5,22:\r Planet demands Treaty..Planet attacks!");
  259.     foremout("G#t>1:p>5,22:\r ");
  260.         if(p->shield > 0) p->shield -= rnd(50);
  261.         if(p->shield <= 0) p->shield = 0;
  262.         rebuild();
  263.       }
  264.     else {
  265.     foremout("G#b>8:\r ");
  266.     foremout("G#p>5,22:\r Planet Market Statistics...");
  267.     planp(cry); 
  268.     mine = 1;   }
  269.          }
  270.     if(c=='M')        /* Mine planet for crystals */
  271.           {
  272.     if(mine) {
  273.     foremout("G#b>12:\r ");
  274.     turn();
  275.     recv = (cry - 10*(pl[p->px].align))/100 + rnd(10);
  276.     foremout("G#p>5,22:\r Amount of Crystals mined from planet is ");
  277.     if(recv<0) recv=0;
  278.     itoa(eex, recv);
  279.     foremout(eex);
  280.     foremout("G#t>1:\r ");
  281.     p->crystal += recv; }
  282.     else {
  283.     foremout("G#p>5,22:\r Planet demands Treaty..Planet attacks!");
  284.     foremout("G#t>1:\r ");
  285.         if(p->shield > 0) p->shield -= rnd(50);
  286.         if(p->shield <= 0) p->shield = 0;
  287.         rebuild();
  288.       }
  289.      }
  290.     if(c=='B')  break;
  291.     if(c=='?')    ;
  292.     }while();
  293. }
  294.  
  295. setscan()
  296. {
  297.     int x, y, ct;
  298.     foremout("G#X>4,9999:S>3,6,4,1:S>2,4,0,0:X>4,47,1,1,638,198,1,?:C>2,1:A>2,8,1:B>308,22,616,132,1:C>1,0:&>352,572,44,0,L,4,x,22,x,132:&>44,110,22,0,L,4,308,x,615,x:\r ");
  299.     foremout("G#C>2,3:A>2,8,1:B>32,147,123,167,1:B>149,147,240,167,1:B>266,147,350,167,1:B>383,147,474,167,1:B>500,147,591,167,1:\r ");
  300.     foremout("G#X>4,47,1,1,638,198,1,?:M>2:C>3,1:A>2,6,1:E>0,9,0:W>52,160,Comm@W>168,160,Orbit@W>285,160,Attack@W>402,160,Bridge@W>519,160,Help@\r ");
  301.     foremout("G#X>4,0,32,147,123,167,1,C:X>4,1,149,147,240,167,1,O:X>4,2,266,147,350,167,1,A:X>4,3,383,147,474,167,1,B:X>4,4,500,147,591,167,1,H:\r ");     
  302.     turn();
  303.     more = 1;
  304.     draw(p->px, NONE);
  305.     for (x=0; x<pc; x++) 
  306.         if (pl[x].ppx == p->px)
  307.             draw(pl[x].ppy, MOON); 
  308.     for (x=0; x<num_recs; x++)
  309.         if (u[x].px == p->px)
  310.         if (strcmp(u[x].name,user)!=0) 
  311.         {   draw(u[x].py, OTHER);
  312.             strcpy(others[more], u[x].name);
  313.             ++more;  }
  314. if(holy) {
  315.     ct = anum = rnd(3);
  316.     while(ct) {
  317.         y = rnd(35);
  318.         if(brd[(p->px)][y] == NONE) {
  319.             brd[(p->px)][y] = ALIEN;
  320.             draw(y, ALIEN);
  321.             --ct;  }    
  322.     } }
  323.     holy = 0;
  324.     x = 0;
  325.     do  {
  326.         y = rnd(35);
  327.         if(brd[(p->px)][y] == NONE) {
  328.             brd[(p->px)][y] = YOU;
  329.             p->py = y;
  330.             draw(y, YOU);
  331.             x = 1;  }
  332.     } while (x == 0);  
  333.  
  334.     for (x=0; x<MAX; x++) 
  335.         if (brd[p->px][x] == ALIEN){
  336.             draw(x, ALIEN); }
  337.  
  338. }
  339.  
  340. attack()
  341. {
  342.     static int x, miss, deter, dmg, zed;
  343. char c;
  344.         foremout("G#X>4,9999:S>3,6,4,1:S>2,4,0,0:X>4,47,1,1,638,198,1,?:C>2,1:A>2,8,1:B>308,22,616,132,1:\r ");
  345.         foremout("G#C>2,3:A>2,8,1:B>32,147,123,167,1:B>149,147,240,167,1:B>266,147,350,167,1:B>383,147,474,167,1:B>500,147,591,167,1:\r ");
  346.         foremout("G#X>4,47,1,1,638,198,1,?:M>2:C>3,1:A>2,6,1:W>52,160,Phasors@W>168,160,Torpedos@W>285,160,Bridge@\r ");
  347.         foremout("G#X>4,0,32,147,123,167,1,P:X>4,1,149,147,240,167,1,T:X>4,2,266,147,350,167,1,B:\r ");     
  348.  
  349.     if(alock==100) {
  350.         showp();
  351.         if(its==0) return;
  352.         aatk = TRUE;
  353.         }
  354. foremout("G#M>1:C>2,3:A>1,1,1:Q>455,44,32,8:C>2,2:A>1,1,1:Q>455,44,18,3:C>2,3:A>3,5,1:B>449,50,459,75,0:T>2,1,17:K>454,105,65,0,175:C>2,2:A>2,8,1:Q>454,76,83,9:\r ");
  355. foremout("G#C>2,1:A>2,6,1:B>387,74,518,79,0:C>2,1:A>2,4,1:O>388,106,19:O>519,106,19:T>2,1,1:\r ");
  356.     
  357. do{    update();
  358.     foremout("G#p>5,22:<>1,2,1:\r ");
  359.     c=foremgetc();
  360.     if(c=='T') { 
  361.         if(p->torpedo == 0 ) rebuild(TORPEDOS);
  362.         if(p->torpedo > 0) {
  363.         foremout("G#b>18:t>1:\r ");      /* 10 - 60 points */
  364.         dmg = 10 + rnd(50); 
  365.         p->torpedo -= 1;
  366.         if(p->torpedo < 0) p->torpedo = 0;  }
  367.         }
  368.     if(c=='P') {
  369.         if(p->phasor == 0 ) rebuild(PHASORS);
  370.         if(p->phasor > 0) {
  371.         foremout("G#b>9:t>1:\r ");       /* 5 - 30 points */
  372.         dmg = 5 + rnd(25); 
  373.         p->phasor -= 1;
  374.         if(p->phasor < 0) p->phasor = 0;  }
  375.         }
  376.     if(c=='?') ;            /* OPPS */
  377.     if(c=='B') break;         /* Back to Bridge  */
  378.     turn();
  379.     deter = rnd(10);
  380.     if(deter > 2) {
  381.         if(aflag) a_dam -= dmg;
  382.         if(aatk) u[q].shield -= dmg;
  383.         if(u[q].shield <=0 && u[q].crystal >4) {
  384.             u[q].shield = 200; u[q].crystal -= 5; }
  385.         if(a_dam <= 0 || u[q].shield <= 0) {
  386.         if(aflag) { p->score += 200; brd[p->px][alock] = NONE; }
  387.         if(aatk) { p->score += 2000; brd[p->px][(u[q].py)] = NONE; u[q].class=0;}
  388.         foremout("G#b>6:&>0,7,1,20,S,4,2,x,0,0:&>7,0,1,20,S,4,2,x,0,0:S>2,4,0,0:C>2,1:A>1,1,1:&>3,120,12,0,Q,4,462,77,x,50:b>6:\r ");    
  389.         foremout("G#p>5,22:\r GOT HIM!");
  390.         a_dam = 60; zed = 1;}
  391.     if(!zed) foremout("G#p>5,22:b>6:&>0,7,1,20,S,4,2,x,0,0:&>7,0,1,20,S,4,2,x,0,0:S>3,6,4,1:S>2,4,0,0:\r Capt, we've HIT our target");
  392.     if(deter < 3) foremout("G#p>5,22:\r We missed our Target, Capt");
  393. combat(); zed = 0; if(alock!=100){
  394. foremout("G#M>1:C>2,3:A>1,1,1:Q>455,44,32,8:C>2,2:A>1,1,1:Q>455,44,18,3:C>2,3:A>3,5,1:B>449,50,459,75,0:T>2,1,17:K>454,105,65,0,175:C>2,2:A>2,8,1:Q>454,76,83,9:\r ");
  395. foremout("G#C>2,1:A>2,6,1:B>387,74,518,79,0:C>2,1:A>2,4,1:O>388,106,19:O>519,106,19:T>2,1,1:\r ");
  396. }
  397. }while();
  398. aatk = 0;
  399. }
  400.  
  401. combat()
  402. {
  403.     int  chance, x;
  404.     aflag = 0; alock=100;
  405.     foremout("G#t>1:p>5,22:\r ");
  406.     for(x=0; x<35; x++)  
  407.     if(brd[(p->px)][x] == ALIEN) {
  408.         aflag = 1;
  409.         alock = x;  }
  410.  
  411.     if(aflag==1 || aatk==1) {
  412.         foremout("G#b>0:\r ");
  413.         chance = rnd(10);
  414.         if (chance > 2)  {        /* 80% chance its a hit  */
  415.         foremout("G#b>6:\r ");        
  416.         foremout("G#p>5,22:&>0,7,1,20,S,4,1,x,0,0:&>7,0,1,20,S,4,1,x,0,0:S>1,0,0,0:S>0,7,7,7:\r Computer reports damage to our structure Capt. ");    
  417.          if(aatk) p->shield -= (5 + rnd(50));
  418.          if(aflag) p->shield -= (5 + rnd(25));
  419.         if(p->shield <= 0) { 
  420.         p->shield = 0; 
  421.         rebuild(SHIELDS); }    
  422.         }
  423.         if(chance < 3) {
  424.             foremout("G#p>5,22:\r The enemy has missed their attack ");
  425.             foremout("G#t>1:\r ");
  426.             }
  427.     }
  428. }
  429.     
  430. planp(dilith)
  431. int dilith;
  432. {
  433. int     x;
  434. static char    eex[10], bigy[80], c; 
  435.  
  436.     foremout("G#M>2:A>0,1,1:B>317,26,607,33,0:E>1,8,0:C>3,0:W>328,32,ALIGN      CLASS   CRYSTALS      NAME@E>0,8,0:\r ");
  437.  
  438.                 strcpy(bigy,"G#W>328,44,");
  439.                 switch(pl[p->px].align) {
  440.                     case 0: strcat(bigy, "FREINDLY  "); break;
  441.                     case 1: strcat(bigy, "NUETRAL   "); break;
  442.                     case 2: strcat(bigy, "HOSTILE   "); break;  }
  443.                 switch(pl[p->px].class) {
  444.                     case 0: strcat(bigy, " POOR    "); break;
  445.                     case 1: strcat(bigy, " NORMAL  "); break;
  446.                     case 2: strcat(bigy, " RICH    "); break;  }
  447.                 itoa(eex, dilith);    
  448.                 strcat(bigy, eex);
  449.                 strcat(bigy, "            ");
  450.                 strcat(bigy, pl[p->px].name);
  451.                 strcat(bigy,"@\r ");
  452.                 foremout(bigy);
  453.  
  454. }
  455.  
  456. showp()
  457. {
  458.     int  x, y, z, poe=42, gain=0, offs=6;
  459. static char eex[10], eey[10], eez[10], bigy[80], c; 
  460.  
  461.     foremout("G#b>8:M>1:C>2,1:A>2,8,1:B>308,22,616,132,1:M>1:C>2,2:A>0,1,1:H>1:B>317,26,607,33,0:B>317,36,606,130,0:E>1,8,0:C>3,0:W>328,32,LIST  CLASS   CRYSTALS      NAME@E>0,8,0:\r ");
  462.     for(x=0; x<more; x++) {
  463.         for(y=0; y<num_recs; y++) {
  464.       if (strcmp(others[x],u[y].name)==0) {
  465.                 strcpy(bigy,"G#W>328,");
  466.                 ++gain;
  467.                 itoa(eex, poe);    
  468.                 strcat(bigy, eex);
  469.                 strcat(bigy, ",");
  470.                 poe += offs;
  471.                 itoa(eey, gain);    
  472.                 strcat(bigy, eey);
  473.                 strcat(bigy, "     ");
  474.                 switch(u[y].class) {
  475.                     case 1: strcat(bigy, "FEDER   "); break;
  476.                     case 2: strcat(bigy, "KLING   "); break;
  477.                     case 3: strcat(bigy, "ROMUL   "); break;  }
  478.                 itoa(eez, u[y].crystal);    
  479.                 strcat(bigy, eez);
  480.                 strcat(bigy,"      ");
  481.                 strcat(bigy, u[y].name);
  482.                 strcat(bigy,"@\r ");
  483.                 foremout(bigy);
  484.                 }}}
  485.  
  486.     if(gain!=0) {
  487.     do  {
  488.         foremout("G#p>5,22:\r Select player by his number above. (0 = Exit) ");
  489.         foremin(stp);
  490.         sscanf(string,"%d", &its);
  491.         if(its<=0) {its=0; break;}
  492.         if(its>more) continue;
  493.         for(x=0; x<num_recs; x++) 
  494.               if (strcmp(others[its],u[x].name)==0) 
  495.                 q = x;
  496.         foremout("G#p>5,22:\r ");
  497.         foremout(u[q].name);
  498.         foremout(" has his ship set on AUTO ATTACK ");
  499.         }while();
  500.         }
  501.     if(gain==0) {
  502.     foremout("G#M>1:C>2,0:A>2,4,1:B>17,173,623,194,1:p>5,22:\r ");
  503.     foremout("G#p>5,22:\r Your all alone here. ");
  504.         its=0;
  505.         }
  506. }
  507.  
  508. grid(pos)        /* look up table for grid position  */
  509. int pos;
  510. {
  511.     switch(pos)  {
  512.         case 0:  a=330 + 0*44; b=33 + 0*22; break;        
  513.         case 1:  a=330 + 1*44; b=33 + 0*22; break;        
  514.         case 2:  a=330 + 2*44; b=33 + 0*22; break;        
  515.         case 3:  a=330 + 3*44; b=33 + 0*22; break;        
  516.         case 4:  a=330 + 4*44; b=33 + 0*22; break;        
  517.         case 5:  a=330 + 5*44; b=33 + 0*22; break;        
  518.         case 6:  a=330 + 6*44; b=33 + 0*22; break;        
  519.  
  520.         case 7:  a=330 + 0*44; b=33 + 1*22; break;        
  521.         case 8:  a=330 + 1*44; b=33 + 1*22; break;        
  522.         case 9:  a=330 + 2*44; b=33 + 1*22; break;        
  523.         case 10:  a=330 + 3*44; b=33 + 1*22; break;        
  524.         case 11:  a=330 + 4*44; b=33 + 1*22; break;        
  525.         case 12:  a=330 + 5*44; b=33 + 1*22; break;        
  526.         case 13:  a=330 + 6*44; b=33 + 1*22; break;        
  527.  
  528.         case 14:  a=330 + 0*44; b=33 + 2*22; break;        
  529.         case 15:  a=330 + 1*44; b=33 + 2*22; break;        
  530.         case 16:  a=330 + 2*44; b=33 + 2*22; break;        
  531.         case 17:  a=330 + 3*44; b=33 + 2*22; break;        
  532.         case 18:  a=330 + 4*44; b=33 + 2*22; break;        
  533.         case 19:  a=330 + 5*44; b=33 + 2*22; break;        
  534.         case 20:  a=330 + 6*44; b=33 + 2*22; break;        
  535.  
  536.         case 21:  a=330 + 0*44; b=33 + 3*22; break;        
  537.         case 22:  a=330 + 1*44; b=33 + 3*22; break;        
  538.         case 23:  a=330 + 2*44; b=33 + 3*22; break;        
  539.         case 24:  a=330 + 3*44; b=33 + 3*22; break;        
  540.         case 25:  a=330 + 4*44; b=33 + 3*22; break;        
  541.         case 26:  a=330 + 5*44; b=33 + 3*22; break;        
  542.         case 27:  a=330 + 6*44; b=33 + 3*22; break;        
  543.  
  544.         case 28:  a=330 + 0*44; b=33 + 4*22; break;        
  545.         case 29:  a=330 + 1*44; b=33 + 4*22; break;        
  546.         case 30:  a=330 + 2*44; b=33 + 4*22; break;        
  547.         case 31:  a=330 + 3*44; b=33 + 4*22; break;        
  548.         case 32:  a=330 + 4*44; b=33 + 4*22; break;        
  549.         case 33:  a=330 + 5*44; b=33 + 4*22; break;        
  550.         case 34:  a=330 + 6*44; b=33 + 4*22; break;        
  551.     }
  552. }
  553.  
  554. turn()
  555. {
  556. static char st[5], bigy[70];
  557.     strcpy(bigy,"G#M>1:C>2,3:A>1,1,1:V>209,91,33,");
  558.     itoa(st, bang);
  559.     strcat(bigy, st);
  560.     strcat(bigy, ",");
  561.     itoa(st, eang);
  562.     strcat(bigy, st);
  563.     strcat(bigy, ":\r ");
  564.     foremout(bigy);
  565.     bang += 10;
  566.     eang += 10;
  567.     turn_left -= 1;
  568.     if(turn_left == 0) {
  569.         foremout("G#p>5,22:\r You have used up all your TURNS -- Sorry Capt. G#t>2:\r ");
  570.         end_game();  }
  571.  
  572. }
  573.  
  574. update()
  575. {
  576. int slev, x;
  577. static char st[5], bigy[27];
  578.     foremout("G#M>2:C>2,0:A>0,1,1:B>167,32,263,38,0:B>167,40,263,46,0:B>167,48,263,54,0:B>167,56,263,62,0:\r ");
  579.     foremout("G#M>1:C>2,1:A>1,1,1:B>168,33,262,37,0:B>168,41,262,45,0:B>168,49,262,53,0:B>168,57,262,61,0:M>1:C>2,2:A>1,1,1:B>102,30,164,91,0:\r ");
  580.     foremout("G#c>0,1:c>1,0:p>14,4:\r ");
  581.     itoa(st,p->shield);
  582.     foremout( st );    
  583.     for(x=0;x<5;x++) st[x]='\0';
  584.     foremout("G#p>14,5:\r ");
  585.     itoa(st,p->phasor);
  586.     foremout( st );    
  587.     for(x=0;x<5;x++) st[x]='\0';
  588.     foremout("G#p>14,6:\r ");
  589.     itoa(st,p->torpedo);
  590.     foremout( st );    
  591.     for(x=0;x<5;x++) st[x]='\0';
  592.     foremout("G#p>14,7:\r ");
  593.     itoa(st,p->energy);
  594.     foremout( st );    
  595.     for(x=0;x<5;x++) st[x]='\0';
  596.     foremout("G#p>14,8:\r ");
  597.     switch(p->class) {
  598.         case 0: /* clear screen / quit game */ break;
  599.         case 1: foremout("Federation "); break;
  600.         case 2: foremout("Klingon ");    break;
  601.         case 3: foremout("Romulan ");    break;  }
  602.     foremout("G#p>14,9:\r ");
  603.     itoa(st,p->score);
  604.     foremout( st );    
  605.     for(x=0;x<5;x++) st[x]='\0';
  606.     foremout("G#p>14,10:\r ");
  607.     itoa(st,p->crystal);
  608.     foremout( st );    
  609.     for(x=0;x<5;x++) st[x]='\0';
  610.     foremout("G#p>14,14:\r ");
  611.     foremout(user);
  612.     foremout("G#C>2,3:\r ");
  613.     slev = (((p->phasor)*94)/ptot) + 168;
  614.     itoa(st, slev);
  615.     strcpy(bigy,"G#B>168,41,");
  616.     strcat(bigy, st);
  617.     strcat(bigy, ",45,0:\r ");
  618.     foremout(bigy);
  619.     slev = (((p->shield)*94)/stot) + 168;
  620.     itoa(st, slev);
  621.     strcpy(bigy,"G#B>168,33,");
  622.     strcat(bigy, st);
  623.     strcat(bigy, ",37,0:\r ");
  624.     foremout(bigy);
  625.     slev = ((p->energy)*94)/etot + 168;
  626.     itoa(st, slev);
  627.     strcpy(bigy,"G#B>168,57,");
  628.     strcat(bigy, st);
  629.     strcat(bigy, ",61,0:\r ");
  630.     foremout(bigy);
  631.     slev = ((p->torpedo)*94)/ttot + 168;
  632.     itoa(st, slev);
  633.     strcpy(bigy,"G#B>168,49,");
  634.     strcat(bigy, st);
  635.     strcat(bigy, ",53,0:\r ");
  636.     foremout(bigy);
  637.     foremout("G#M>1:C>2,0:A>2,4,1:B>17,173,623,194,1:c>0,0:c>1,3:p>5,22:\r ");
  638.     
  639. }
  640.  
  641. rebuild(it)
  642. int it;
  643. {
  644.     switch(it) {
  645.     case SHIELDS:
  646.         if(p->shield==0 && p->crystal > 4) {
  647.             p->crystal -= 5;
  648.             p->shield = stot;
  649.             update();  }
  650.         else { 
  651.             foremout("G#p>5,22:\r You have been destroyed. Better Luck Next Time! G#t>1:\r ");
  652.             p->class = 0;
  653.             end_game();  }
  654.         break;
  655.     case TORPEDOS:
  656.         if(p->torpedo==0 && p->crystal > 4) {
  657.             p->crystal -= 5;
  658.             p->torpedo = ttot;
  659.             update();  }
  660.         else 
  661.             foremout("G#p>5,22:\r We have no more crystals to replenish torpedos! ");
  662.         break;
  663.     case ENGINES:
  664.         if(p->energy==0 && p->crystal > 4) {
  665.             p->crystal -= 5;
  666.             p->energy = etot;
  667.             update();  }
  668.         else 
  669.             foremout("G#p>5,22:\r We have no more crystals to supply energy! ");
  670.         break;
  671.     case PHASORS:
  672.         if(p->phasor==0 && p->crystal > 4) {
  673.             p->crystal -= 5;
  674.             p->phasor = ptot;
  675.             update();  }
  676.         else 
  677.             foremout("G#p>5,22:\r We have no more crystals to replenish phasor banks! ");
  678.         break;
  679.     }
  680. }
  681.  
  682. end_game()
  683. {
  684.     save();
  685.     foremout("G#:I>0:s>0:S>2,7,0,0:S>3,0,7,0:k>1:\r ");
  686.     Pterm(0);
  687. }
  688. add_p()
  689. {
  690.     int x; 
  691.  
  692.     x = num_recs;
  693.     do {
  694.         u[x].px = rnd(MAX);   
  695.         u[x].py = rnd(MAX);
  696.         }
  697.     while (brd[ (u[x].px )][ (u[x].py )] != NONE);
  698.     brd[ (u[x].px )][ (u[x].py )] = YOU;    
  699.     strcpy(u[x].name, user);
  700.     u[x].energy = etot;
  701.     u[x].phasor = ptot;
  702.     u[x].torpedo = ttot;
  703.     u[x].shield = stot;
  704.     u[x].crystal = 5;
  705.     u[x].score = 0;
  706.     u[x].class = rnd(3) + 1;
  707.     p = &u[x];
  708.     ++num_recs;    
  709.  
  710. }
  711.  
  712. load()
  713. {
  714.    FILE *p_file;
  715.    int  x, found=0;
  716.   
  717.     get_foremdat();
  718.     if((p_file = fopen("trek.dat", "r")) == NULL) {
  719.          add_p();
  720.          save();
  721.          return;
  722.       }
  723.    fscanf(p_file, "%d", &num_recs);
  724.  
  725.    for (x=0; x<num_recs; x++) {
  726.       fscanf(p_file, "%s", u[x].name);
  727.          
  728.       fscanf(p_file, "%d", &u[x].px);
  729.       fscanf(p_file, "%d", &u[x].py);
  730.       fscanf(p_file, "%d", &u[x].energy);
  731.       fscanf(p_file, "%d", &u[x].phasor);
  732.       fscanf(p_file, "%d", &u[x].torpedo);
  733.       fscanf(p_file, "%d", &u[x].shield);
  734.       fscanf(p_file, "%d", &u[x].crystal);
  735.       fscanf(p_file, "%d", &u[x].score);
  736.       fscanf(p_file, "%d", &u[x].class);
  737.       fscanf(p_file, "%s", u[x].rec_messg);
  738.       brd[(u[x].px)][(u[x].py)] = OTHER;
  739.       if (strcmp(u[x].name, user)==0) {
  740.           brd[(u[x].px)][(u[x].py)] = YOU;
  741.           p = &u[x];                           /* player p is present */
  742.           found = 1;
  743.           }
  744.       }
  745.       if(found!=1)          /* player is new */
  746.            add_p();
  747.             save();
  748.     fclose(p_file);
  749. }
  750.  
  751. save()
  752. {
  753.    FILE *p_file;
  754. static int x, killp, count;
  755.  
  756.       for(x=0; x<num_recs; x++)  {
  757.         if(u[x].class == 0)
  758.             ++killp;
  759.     }
  760.         count = num_recs - killp;                    
  761.             p_file = fopen("trek.dat", "w");
  762.       fprintf(p_file, "%d\n", count);
  763.       for (x=0; x<num_recs; ++x) {
  764.         if(u[x].class != 0) {
  765.       fprintf(p_file, "%s\n", u[x].name);   
  766.       fprintf(p_file, "%d\n", u[x].px);
  767.       fprintf(p_file, "%d\n", u[x].py);
  768.       fprintf(p_file, "%d\n", u[x].energy);
  769.       fprintf(p_file, "%d\n", u[x].phasor);
  770.       fprintf(p_file, "%d\n", u[x].torpedo);
  771.       fprintf(p_file, "%d\n", u[x].shield);
  772.       fprintf(p_file, "%d\n", u[x].crystal);
  773.       fprintf(p_file, "%d\n", u[x].score);
  774.       fprintf(p_file, "%d\n", u[x].class);
  775.       fprintf(p_file, "%s\n", u[x].rec_messg); }
  776.       }
  777.       fclose(p_file);
  778. }
  779.  
  780. planet()
  781. {
  782.    FILE *p_file;
  783.    int x=0, peer, tip=0;
  784.  
  785.  
  786.          if( (p_file = fopen("planet.dat", "r"))==NULL) {
  787.         tip = 1;
  788.     p_file = fopen("planet.dat", "w");
  789.     for (x=0; x<MAX; x++)  {
  790.         peer = rnd(4);
  791.         if(peer<3)  {
  792.         pl[pc].ppx = x;
  793.         pl[pc].ppy = rnd(MAX);
  794.         pl[pc].align = rnd(3);
  795.         pl[pc].class = rnd(3);
  796.         ++pc;  } 
  797.         }    
  798.           fprintf(p_file, "%d\n", pc); 
  799.     for(x=0; x<pc; x++)  {    
  800.            fprintf(p_file, "%d\n", pl[x].ppx);
  801.               fprintf(p_file, "%d\n", pl[x].ppy);   
  802.               fprintf(p_file, "%d\n", pl[x].align);
  803.               fprintf(p_file, "%d\n", pl[x].class);
  804.               fprintf(p_file, "%s\n", list[x]);
  805.           } 
  806.     }
  807.     if(tip==0) {
  808.        fscanf(p_file, "%d", &pc);
  809.        for (x=0; x<pc; x++) {
  810.               fscanf(p_file, "%d\n", &pl[x].ppx);
  811.               fscanf(p_file, "%d\n", &pl[x].ppy);
  812.               fscanf(p_file, "%d\n", &pl[x].align);   
  813.               fscanf(p_file, "%d\n", &pl[x].class);
  814.             fscanf(p_file, "%s\n", pl[x].name);
  815.         }
  816.     }
  817.  
  818.     for(x=0; x<pc; x++)
  819.         brd[(pl[x].ppx)][(pl[x].ppy)] = MOON;
  820.           fclose(p_file); 
  821. }
  822.  
  823.  
  824. get_foremdat()
  825.   {
  826.   FILE *fd;
  827.     int x;
  828.   fd=fopen("C:\\FOREM\\DOORS\\DORINFO1.DEF","r");
  829.   if(fd==NULL) Pterm(0);
  830.   for(x=0; x<7; x++)
  831.       fgets(user, 30, fd);
  832.   fclose(fd);
  833.   }  
  834.     
  835.  
  836. foremout(string1)
  837. char *string1;
  838. {
  839. int i,j;
  840. char teken;
  841. j = strlen(string1);
  842. /*for(i=0; i<j; i++) string[i] = '\0';
  843. strcpy(string , string1);*/
  844.  
  845. for(i=0;i<j;i++)
  846.      {
  847.      teken = *string1;
  848.     /* Bconout(2,(int)teken);      */   
  849.      if (calltype)                  
  850.           {
  851.           if (!carrier()) return 1; 
  852.           Bconout(1,(int)teken);     
  853.           }
  854.       string1++;                     
  855.       }
  856.     sflush(); 
  857. return 0;                            /* Good return   */
  858. }
  859.  
  860. foremin(string1)
  861. char *string1;
  862. {
  863. char teken = 0x00;
  864. int console=0,modem=0,flag = 0;
  865. int aantal = 0;
  866. timeinfo tijd,tijd1;
  867. tijd.realtime = Tgettime();
  868. while( (!calltype || (carrier())) && (teken != 13))
  869.      {
  870.      if ( ( (modem = Bconstat(1)) ) || ( (console = Bconstat(2)) ) )
  871.           {
  872.           tijd.realtime = Tgettime();
  873.           flag = 0;
  874.           teken = (char)(Bconin( (-modem) + (2*(-console)) )) & 0x00FF;
  875.           if (teken == '\b')                  /* backspace */
  876.                {
  877.                aantal--;
  878.                if (aantal<0) aantal = 0;
  879.                else
  880.                     {
  881.                     foremputc(teken);
  882.                     foremputc(' ');
  883.                     foremputc('\b');
  884.                     string1--;
  885.                     }
  886.                }
  887.           else /*if (isprint(teken))*/
  888.                {
  889.                foremputc(teken);
  890.                *string1 = teken;
  891.                string1++;
  892.                aantal++;
  893.                }
  894.           }
  895.      tijd1.realtime = Tgettime();
  896.      if (tijd1.realtime - tijd.realtime >= 30)
  897.           {
  898.           foremout("\r\nTimeout, program terminating....\r\n");
  899.           save();
  900.           Pterm(0);
  901.           return 1;
  902.           }
  903.      else if ( (tijd1.realtime - tijd.realtime >= 15) && !flag)
  904.           {
  905.           foremout("\r\n30 seconds until time-out termination.\r\n");
  906.           flag = 1;
  907.           } 
  908.      }
  909. foremout("\r ");
  910. *string1 = (char)0;
  911. if (calltype) return !carrier();
  912. else return 0;
  913. }
  914.  
  915. foremputc(teken)
  916. char teken;
  917. {
  918. Bconout(2,(int)teken);
  919. if (calltype)    /* if this is a remote call */
  920.      {
  921.      while (Bcostat(1)==0)
  922.          {
  923.          if (!carrier()) return 1;
  924.          }
  925.      Bconout(1,(int)teken);
  926.      }
  927. return 0;
  928. }
  929.  
  930. foremgetc() 
  931. {
  932. char teken, bat;
  933. int console = 0,modem = 0,flag = 0,loss=1024;
  934. timeinfo tijd,tijd1;
  935. tijd.realtime = Tgettime();
  936. while( !calltype || (carrier()) )
  937.      {
  938.      if ( ( (modem = Bconstat(1)) ) || ( (console = Bconstat(2)) ) )
  939.           {
  940.           tijd.realtime = Tgettime();
  941.           flag = 0;
  942.           teken = (char)((Bconin( (-modem) + (2*(-console)) )) & 0x00FF);
  943.           return teken;
  944.           }
  945.     tijd1.realtime = Tgettime();
  946.      if (tijd1.realtime - tijd.realtime >= 30)
  947.           {
  948.           foremout("\r\nTimeout, program terminating....\r\n");
  949.           Pterm(0);
  950.           return loss;
  951.           }
  952.      else if ( (tijd1.realtime - tijd.realtime == 15) && !flag)
  953.           {
  954.           foremout("\r\n30 seconds until time-out termination.\r\n");
  955.           flag = 1;
  956.           } 
  957.      }
  958. return loss;
  959. }
  960.     
  961. carrier()      /* returns 1 if carrier present, 0 if not */
  962. {
  963. long save_ssp;
  964. int carrier;
  965. char *carptr;
  966. carptr = (char *)0xfffa01L;
  967. save_ssp = Super(0L);
  968. carrier = (!((*carptr) & 2));
  969. Super(save_ssp);
  970. if(!carrier)
  971.     {
  972.     save();
  973.     Pterm(0);
  974.     }
  975. return carrier;
  976. }
  977.  
  978. /* This function clears input buffers */
  979.  
  980. sflush()
  981. {
  982. int fl;
  983. while(Bconstat(AUX))
  984. fl=Bconin(AUX);
  985. while(Bconstat(CON))
  986. fl=Bconin(CON);
  987. }
  988.  
  989. rnd(n)
  990. int n;
  991. {
  992.     int r;
  993.     r=(int) Random();
  994.     r=abs(r)%n;
  995.     return(r);
  996. }
  997.