home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d01xx / d0178.lha / Cosmic / human.c < prev    next >
C/C++ Source or Header  |  1989-02-04  |  45KB  |  1,636 lines

  1. struct IntuiText DText=
  2.   {
  3.   GREENPEN,BLACKPEN,
  4.   JAM2,
  5.   0,0,
  6.   NULL,
  7.   NULL,
  8.   NULL
  9.   };
  10. struct IntuiMessage *mes;
  11. int screen1,screen2;
  12. int show1,show2;
  13. int showpla1,showpla2;
  14. int sort[STARNO],dis[STARNO],sortsta;
  15.  
  16. human(pla)
  17. int pla;
  18.   {
  19.   int i;
  20.   struct NCommand c;
  21.   c.com=DUMMY;
  22.   screen1=PLAYERSUMMARY;
  23.   screen2=CLEAR;
  24.   sortsta=-1;
  25.   make_displ(pla);
  26.   while((c.com=input_action(0,pla))>=0)
  27.     {
  28.     switch(c.com)
  29.       {
  30.       case POSSESS:
  31.         c.par[0]=input_star(1,pla);
  32.         c.par[1]=input_planet(2,pla);
  33.         break;
  34.       case LAND:
  35.         c.par[0]=input_task(1,pla);
  36.         c.par[1]=input_planet(2,pla);
  37.         break;
  38.       case CARRY:
  39.         c.par[0]=input_task(1,pla);
  40.         input_ships_task(2,pla,&c);
  41.         break;
  42.       case DESTINATION:
  43.         c.par[0]=input_task(1,pla);
  44.         c.par[1]=input_star(2,pla);
  45.         break;
  46.       case EMIGRATION:
  47.         c.par[0]=input_star(1,pla);
  48.         c.par[1]=input_planet(2,pla);
  49.         c.par[2]=input_number(3,pla,star[c.par[0]].planet[c.par[1]].population);
  50.         break;
  51.       case JOIN:
  52.         input_many_tasks(1,pla,&c);
  53.         break;
  54.       case KILL:
  55.         c.par[0]=input_star(1,pla);
  56.         c.par[1]=input_planet_or_ret(2,pla);
  57.         break;
  58.       case SPLIT:
  59.         c.par[0]=input_task(1,pla);
  60.         input_ships_task(2,pla,&c);
  61.         break;
  62.       case PRODUCE:
  63.         c.par[0]=input_star(1,pla);
  64.         c.par[1]=input_planet(2,pla);
  65.         c.par[2]=input_product(3,pla,general.techlevel[pla]);
  66.         break;
  67.       case DECLARE:
  68.         c.par[0]=input_player(1,pla);
  69.         c.par[1]=input_status(2,pla,general.relation[pla][c.par[0]]);
  70.         break;
  71.       default:break;/*ERROR*/
  72.       }
  73.     do_command(pla,&c);
  74.     make_displ(pla);
  75.     }
  76.   }
  77. make_displ(pla)
  78. int pla;
  79.   {
  80.   mapdisplay(pla);
  81.   if (screen1==STARSUMMARY) starsummary(pla,show1);
  82.   if (screen2==TASKSUMMARY) tasksummary(pla,showpla2,show2);
  83.   if (screen1==PLAYERSUMMARY) showstatus(pla);
  84.   if (screen2==TASKOVERVIEW) showtasks(pla,showpla2,show2);
  85.   if (screen2==SHIPOVERVIEW) tshipsummary(pla,showpla2,show2);
  86.   if (screen1==STAROVERVIEW) showstars(pla);
  87.   if (screen2==SHIPSUMMARY) shipsummary(pla,show2);
  88.   if (screen2==PLANETSUMMARY) planetsummary(pla,show2,showpla2);
  89.   }
  90. input_action(line,pla)
  91. int line;
  92. int pla;
  93.   {
  94.   int c,i,p;
  95.   char *str;
  96.   switch(cget(pla))
  97.     {
  98.     case 'p':
  99.       str="Possess planet";
  100.       c=POSSESS;
  101.       break;
  102.     case 'g':
  103.       return(-1);
  104.     case 'c':
  105.       str="Carry ships";
  106.       c=CARRY;
  107.       break;
  108.     case 'h':
  109.       str="Hyperspace Tf";
  110.       c=DESTINATION;
  111.       break;
  112.     case 'e':
  113.       str="Emigration";
  114.       c=EMIGRATION;
  115.       break;
  116.     case 'l':
  117.       str="Land on planet";
  118.       c=LAND;
  119.       break;
  120.     case 'j':
  121.       str="Join taskforces";
  122.       c=JOIN;
  123.       break;
  124.     case 'k':
  125.       str="Kill";
  126.       c=KILL;
  127.       break;
  128.     case 'n':
  129.       str="New Taskforce from";
  130.       c=SPLIT;
  131.       break;
  132.     case 'b':
  133.       str="Build";
  134.       c=PRODUCE;
  135.       break;
  136.     case 'd':
  137.       str="Diplomacy";
  138.       c=DECLARE;
  139.       break;
  140.     case '?':
  141.       showhelp();
  142.       return(DUMMY);
  143.     case 's':
  144.       SetAPen(ConPort,BLACKPEN);
  145.       RectFill(ConPort,400L,0L,639L,39L);
  146.       DText.FrontPen=GREENPEN;
  147.       DText.IText=(UBYTE *) "SHOW  >Starsummary";
  148.       PrintIText(ConPort,&DText,400L,8L*line);
  149.       show1=input_star_or_ret(1,pla);
  150.       if(show1==STARNO) screen1=STAROVERVIEW;
  151.       showpla1=input_planet_or_ret(2,pla);
  152.       if(showpla1==PLANETNO) screen1=STARSUMMARY;
  153.                         else screen1=PLANETSUMMARY;
  154.       return(DUMMY);
  155.     case 't':
  156.       SetAPen(ConPort,BLACKPEN);
  157.       RectFill(ConPort,400L,0L,639L,39L);
  158.       DText.FrontPen=GREENPEN;
  159.       DText.IText=(UBYTE *) "SHOW  >Taskforcesummary";
  160.       PrintIText(ConPort,&DText,400L,8L*line);
  161.       showpla2=input_player(1,pla);
  162.       show2=input_task_or_ret(2,pla);
  163.       if(show2==TASKNO) screen2=TASKOVERVIEW;
  164.                    else screen2=TASKSUMMARY;
  165.       return(DUMMY);
  166.     case 'z':
  167.       SetAPen(ConPort,BLACKPEN);
  168.       RectFill(ConPort,400L,0L,639L,39L);
  169.       DText.FrontPen=GREENPEN;
  170.       DText.IText=(UBYTE *) "SHOW  >Status";
  171.       PrintIText(ConPort,&DText,400L,8L*line);
  172.       screen1=PLAYERSUMMARY;
  173.       return(DUMMY);
  174.     case 'f':
  175.       SetAPen(ConPort,BLACKPEN);
  176.       RectFill(ConPort,400L,0L,639L,39L);
  177.       DText.FrontPen=GREENPEN;
  178.       DText.IText=(UBYTE *) "SHOW  >Shipsummary";
  179.       PrintIText(ConPort,&DText,400L,8L*line);
  180.       showpla2=input_player_or_ret(1,pla);
  181.       show2=input_ship(2,pla);
  182.       if(showpla2==PLAYERNO) screen2=SHIPSUMMARY;
  183.                         else screen2=SHIPOVERVIEW;
  184.       return(DUMMY);
  185.     default:
  186.       str="Unknown command.";
  187.       c=ERROR;
  188.       break;
  189.     }
  190.   SetAPen(ConPort,BLACKPEN);
  191.   RectFill(ConPort,400L,0L,639L,39L);
  192.   DText.FrontPen=GREENPEN;
  193.   DText.IText=(UBYTE *) "ACTION>";
  194.   PrintIText(ConPort,&DText,400L,8L*line);
  195.   DText.IText=(UBYTE *)str;
  196.   PrintIText(ConPort,&DText,456L,8L*line);
  197.   return(c);
  198.   }
  199. input_task(line,pla)
  200. int line;
  201. int pla;
  202.   {
  203.   int c,tas;
  204.   DText.FrontPen=GREENPEN;
  205.   DText.IText=(UBYTE *) "TF    >";
  206.   PrintIText(ConPort,&DText,400L,8L*line);
  207.   tas=TASKNO+1;
  208.   while(tas>=TASKNO)
  209.     {
  210.     c=cget(pla);
  211.     if(c>='a' && c<='z') tas=c-'a';
  212.     if(c>='A' && c<='Z') tas=c-'A'+SECSET;
  213.     }
  214.   DText.IText=(UBYTE *)" ";
  215.   DText.IText[0]=(UBYTE) c;
  216.   PrintIText(ConPort,&DText,456L,8L*line);
  217.   return(tas);
  218.   }
  219. input_task_or_ret(line,pla)
  220. int line;
  221. int pla;
  222.   {
  223.   int c,tas;
  224.   DText.FrontPen=GREENPEN;
  225.   DText.IText=(UBYTE *) "TF    >";
  226.   PrintIText(ConPort,&DText,400L,8L*line);
  227.   tas=TASKNO+1;
  228.   while(tas>TASKNO)
  229.     {
  230.     c=cget(pla);
  231.     if(c>='a' && c<='z') tas=c-'a';
  232.     if(c>='A' && c<='Z') tas=c-'A'+SECSET;
  233.     if(c==0x0d) tas=TASKNO;
  234.     }
  235.   if(tas==TASKNO) return(TASKNO);
  236.   DText.IText=(UBYTE *)" ";
  237.   DText.IText[0]=(UBYTE) c;
  238.   PrintIText(ConPort,&DText,456L,8L*line);
  239.   return(tas);
  240.   }
  241. input_ships_task(line,pla,co)
  242. int line;
  243. int pla;
  244. struct NCommand *co;
  245.   {
  246.   int i,tas;
  247.   tas=co->par[0];
  248.   for(i=0;i<SHIPNO;i++)
  249.     {
  250.     co->par[i+1]=0;
  251.     if(INTASK(pla,tas,i)==0 || task[pla][tas].headed==-1) continue;
  252.     SetAPen(ConPort,BLACKPEN);
  253.     RectFill(ConPort,400L,line*8L,639L,line*8L+15);
  254.     SetAPen(ConPort,GREENPEN);
  255.     DText.IText=(UBYTE *)ship[i].name;
  256.     PrintIText(ConPort,&DText,400L,line*8L);
  257.     co->par[i+1]=input_number(line+1,pla,INTASK(pla,tas,i));
  258.     }
  259.   return();
  260.   }
  261. input_many_tasks(line,pla,co)
  262. int line;
  263. int pla;
  264. struct NCommand *co;
  265.   {
  266.   int c,i;
  267.   i=0;
  268.   DText.FrontPen=GREENPEN;
  269.   DText.IText=(UBYTE *) "TFS   >";
  270.   PrintIText(ConPort,&DText,400L,8L*line);
  271.   DText.IText=(UBYTE *)" ";
  272.   while(1)
  273.     {
  274.     c=cget(pla);
  275.     if(c==0x0d)
  276.       {
  277.       co->par[i]=TASKNO;
  278.       break;
  279.       }
  280.     if(c>='a' && c<='z' && c-'a'<TASKNO)
  281.       {
  282.       co->par[i]=c-'a';
  283.       DText.IText[0]=(UBYTE) c;
  284.       PrintIText(ConPort,&DText,456L+8L*i,8L*line);
  285.       i++;
  286.       }
  287.     if(c>='A' && c<='Z' && c-'A'+SECSET<TASKNO)
  288.       {
  289.       co->par[i]=c-'A'+SECSET;
  290.       DText.IText[0]=(UBYTE) c;
  291.       PrintIText(ConPort,&DText,456L+8L*i,8L*line);
  292.       i++;
  293.       }
  294.     if(i>22)
  295.       {
  296.       co->par[i]=TASKNO;
  297.       break;
  298.       }
  299.     }
  300.   }
  301. input_star(line,pla)
  302. int line;
  303. int pla;
  304.   {
  305.   int sta;
  306.   DText.FrontPen=GREENPEN;
  307.   DText.IText=(UBYTE *) "STAR  >";
  308.   PrintIText(ConPort,&DText,400L,8L*line);
  309.   while( (sta=cget(pla)-'a') <0 || sta>=STARNO );
  310.   DText.IText=(UBYTE *)" ";
  311.   DText.IText[0]=(UBYTE) sta+'A';
  312.   PrintIText(ConPort,&DText,456L,8L*line);
  313.   return(sta);
  314.   }
  315. input_star_or_ret(line,pla)
  316. int line;
  317. int pla;
  318.   {
  319.   int sta;
  320.   DText.FrontPen=GREENPEN;
  321.   DText.IText=(UBYTE *) "STAR  >";
  322.   PrintIText(ConPort,&DText,400L,8L*line);
  323.   while( ((sta=cget(pla)-'a') <0 || sta>=STARNO) && sta!=0x0d-'a' );
  324.   if(sta==0x0d-'a') return(STARNO);
  325.   DText.IText=(UBYTE *)" ";
  326.   DText.IText[0]=(UBYTE) sta+'A';
  327.   PrintIText(ConPort,&DText,456L,8L*line);
  328.   return(sta);
  329.   }
  330. input_player_or_ret(line,pla)
  331. int line;
  332. int pla;
  333.   {
  334.   int c,d=PLAYERNO;
  335.   DText.FrontPen=GREENPEN;
  336.   DText.IText=(UBYTE *) "POWER >None";
  337.   PrintIText(ConPort,&DText,400L,8L*line);
  338.   while(1)
  339.     {
  340.     c=cget(pla);
  341.     if(c>='a' && (c-'a')<PLAYERNO)
  342.       {
  343.       d=c-'a';
  344.       c=0x0d;
  345.       }
  346.     if(c==',' && d>0)
  347.       {
  348.       d--;
  349.       }
  350.     if(c=='.' && d<PLAYERNO)
  351.       {
  352.       d++;
  353.       }
  354.     SetAPen(ConPort,BLACKPEN);
  355.     RectFill(ConPort,456L,line*8L,639L,line*8L+7L);
  356.     SetAPen(ConPort,GREENPEN);
  357.     if(d<PLAYERNO)
  358.       {
  359.       DText.FrontPen=PLAYERPEN(d);
  360.       DText.IText=(UBYTE *)general.pname[d];
  361.       PrintIText(ConPort,&DText,456L,8L*line);
  362.       }
  363.     else
  364.       {
  365.       DText.FrontPen=GREENPEN;
  366.       DText.IText=(UBYTE *)"None";
  367.       PrintIText(ConPort,&DText,456L,8L*line);
  368.       }
  369.     if(c==0x0d)
  370.       {
  371.       DText.FrontPen=GREENPEN;
  372.       return(d);
  373.       }
  374.     }
  375.   }
  376. input_planet(line,pla)
  377. int line;
  378. int pla;
  379.   {
  380.   int c;
  381.   DText.FrontPen=GREENPEN;
  382.   DText.IText=(UBYTE *) "PLANET>";
  383.   PrintIText(ConPort,&DText,400L,8L*line);
  384.   while((c=cget(pla))<'0' || c>'9');
  385.   DText.IText=(UBYTE *)" ";
  386.   DText.IText[0]=(UBYTE) c;
  387.   PrintIText(ConPort,&DText,456L,8L*line);
  388.   return(c-'0');
  389.   }
  390. input_planet_or_ret(line,pla)
  391. int line;
  392. int pla;
  393.   {
  394.   int c;
  395.   DText.FrontPen=GREENPEN;
  396.   DText.IText=(UBYTE *) "PLANET>";
  397.   PrintIText(ConPort,&DText,400L,8L*line);
  398.   while(((c=cget(pla))<'0' || c>'9') && c!=0x0d);
  399.   if(c==0x0d) return(PLANETNO);
  400.   DText.IText=(UBYTE *)" ";
  401.   DText.IText[0]=(UBYTE) c;
  402.   PrintIText(ConPort,&DText,456L,8L*line);
  403.   return(c-'0');
  404.   }
  405. input_ship_in_task(line,pla,tas)
  406. int line;
  407. int pla;
  408. int tas;
  409.   {
  410.   int c,d,e;
  411.   DText.FrontPen=GREENPEN;
  412.   for(d=0;d<SHIPNO;d++) if(INTASK(pla,tas,d)) break;
  413.   DText.IText=(UBYTE *) "SHIP  >";
  414.   PrintIText(ConPort,&DText,400L,8L*line);
  415.   if (d==SHIPNO) return(0);
  416.   DText.IText=(UBYTE *)ship[d].name;
  417.   PrintIText(ConPort,&DText,456L,8L*line);
  418.   while(1)
  419.     {
  420.     c=cget(pla);
  421.     if(c>='a' && (c-'a')<SHIPNO && INTASK(pla,tas,c-'a'))
  422.       {
  423.       d=c-'a';
  424.       c=0x0d;
  425.       }
  426.     if(c==',')
  427.       {
  428.       e=d-1;
  429.       for(;e>=0;e--) if(INTASK(pla,tas,e)) break;
  430.       if(e>=0) d=e;
  431.       }
  432.     if(c=='.')
  433.       {
  434.       e=d+1;
  435.       for(;e<SHIPNO;e++) if(INTASK(pla,tas,e)) break;
  436.       if(e<SHIPNO) d=e;
  437.       }      
  438.     SetAPen(ConPort,BLACKPEN);
  439.     RectFill(ConPort,456L,line*8L,639L,line*8L+7L);
  440.     SetAPen(ConPort,GREENPEN);
  441.     DText.IText=(UBYTE *)ship[d].name;
  442.     PrintIText(ConPort,&DText,456L,8L*line);
  443.     if(c==0x0d) return(d);
  444.     }
  445.   }
  446. input_product(line,pla,tech)
  447. int line;
  448. int pla;
  449. int tech;
  450.   {
  451.   int c,d=RESEARCHING,e;
  452.   DText.FrontPen=GREENPEN;
  453.   DText.IText=(UBYTE *) "BUILD >";
  454.   PrintIText(ConPort,&DText,400L,8L*line);
  455.   DText.IText=(UBYTE *)"Researching";
  456.   PrintIText(ConPort,&DText,456L,8L*line);
  457.   while(1)
  458.     {
  459.     c=cget(pla);
  460.     if(c>='a' && (c-'a')<SHIPNO && ship[c-'a'].techlevel<=tech)
  461.       {
  462.       d=c-'a';
  463.       c=0x0d;
  464.       }
  465.     if(c=='M') {d=MINING;c=0x0d;}
  466.     if(c=='I') {d=INVESTING;c=0x0d;}
  467.     if(c=='R') {d=RESEARCHING;c=0x0d;}
  468.     if(c==',')
  469.       {
  470.       e=d-1;
  471.       if(e<SHIPNO)
  472.         {
  473.         for(;e>=0;e--) if(ship[e].techlevel<=tech&&!(ship[e].special&NOTPROD)) break;
  474.         if(e>=0) d=e;
  475.         }
  476.       else d=e;
  477.       }
  478.     if(c=='.')
  479.       {
  480.       e=d+1;
  481.       if(e>=SHIPNO)
  482.         {
  483.         if(e<DO_NOTHING) d=e;
  484.         }
  485.       else
  486.         {
  487.         for(;e<SHIPNO;e++) if(ship[e].techlevel<=tech&&!(ship[e].special&NOTPROD)) break;
  488.         d=e;
  489.         }
  490.       }
  491.     SetAPen(ConPort,BLACKPEN);
  492.     RectFill(ConPort,456L,line*8L,639L,line*8L+7L);
  493.     SetAPen(ConPort,GREENPEN);
  494.     if(d<SHIPNO && !(ship[d].special&NOTPROD)) DText.IText=(UBYTE *)ship[d].name;
  495.     if(d==RESEARCHING) DText.IText=(UBYTE *)"Researching";
  496.     if(d==MINING) DText.IText=(UBYTE *)"Mining";
  497.     if(d==INVESTING) DText.IText=(UBYTE *)"Investing";
  498.     PrintIText(ConPort,&DText,456L,8L*line);
  499.     if(c==0x0d) return(d);
  500.     }
  501.   }
  502. input_ship(line,pla)
  503. int line;
  504. int pla;
  505.   {
  506.   int c,d=SHIPNO-1,e;
  507.   DText.FrontPen=GREENPEN;
  508.   DText.IText=(UBYTE *) "SHIP  >";
  509.   PrintIText(ConPort,&DText,400L,8L*line);
  510.   DText.IText=(UBYTE *)ship[d].name;
  511.   PrintIText(ConPort,&DText,456L,8L*line);
  512.   while(1)
  513.     {
  514.     c=cget(pla);
  515.     if(c>='a' && (c-'a')<SHIPNO)
  516.       {
  517.       d=c-'a';
  518.       c=0x0d;
  519.       }
  520.     if(c==',')
  521.       {
  522.       for(e=d-1;e>=0;e--) if(ship[e].name[0]!='\0') break;
  523.       if(e>=0) d=e;
  524.       }
  525.     if(c=='.')
  526.       {
  527.       for(e=d+1;e<SHIPNO;e++) if(ship[e].name[0]!='\0')break;
  528.       if(e<SHIPNO) d=e;
  529.       }
  530.     SetAPen(ConPort,BLACKPEN);
  531.     RectFill(ConPort,456L,line*8L,639L,line*8L+7L);
  532.     SetAPen(ConPort,GREENPEN);
  533.     DText.IText=(UBYTE *)ship[d].name;
  534.     PrintIText(ConPort,&DText,456L,8L*line);
  535.     if(c==0x0d) return(d);
  536.     }
  537.   }
  538. input_status(line,pla,status)
  539. int line;
  540. int pla;
  541. int status;
  542.   {
  543.   int c;
  544.   DText.FrontPen=GREENPEN;
  545.   DText.IText=(UBYTE *) "STATUS>";
  546.   PrintIText(ConPort,&DText,400L,8L*line);
  547.   DText.IText=(UBYTE *) "        ";
  548.   pstr(status,DText.IText);
  549.   PrintIText(ConPort,&DText,456L,8L*line);
  550.   while(1)
  551.     {
  552.     c=cget(pla);
  553.     if(c==',' && status>RELMIN) status--;
  554.     if(c=='.' && status<RELMAX) status++;
  555.     if(c=='w') {status=WAR;c=0x0d;}
  556.     if(c=='p') {status=PEACE;c=0x0d;}
  557.     if(c=='a') {status=ALLIANCE;c=0x0d;}
  558.     pstr(status,DText.IText);
  559.     PrintIText(ConPort,&DText,456L,8L*line);
  560.     if(c==0x0d) return(status);
  561.     }
  562.   }
  563. input_number(line,pla,max)
  564. int line;
  565. int pla;
  566. int max;
  567.   {
  568.   int pos,c,d=0;
  569.   DText.FrontPen=GREENPEN;
  570.   DText.IText=(UBYTE *)"NUMBER>000(000)";
  571.   mstr(max,DText.IText+11);
  572.   PrintIText(ConPort,&DText,400L,line*8L);
  573.   if(max<=0) return(0);
  574.   DText.IText=(UBYTE *)"000";
  575.   while(1)
  576.     {
  577.     c=coget();
  578.     if(c=='.' && d<max) d++;
  579.     if(c==',' && d>0) d--;
  580.     if(c>='0' && c<='9' && (c-'a')<=max)
  581.       {
  582.       d=c-'0';
  583.       c=0x0d;
  584.       }
  585.     if(c=='>') d=max;
  586.     if(c=='<') d=0;
  587.     mstr(d,DText.IText);
  588.     PrintIText(ConPort,&DText,456L,line*8L);
  589.     if(c==0x0d) return(d);
  590.     }
  591.   }
  592. input_player(line,pla)
  593. int line;
  594. int pla;
  595.   {
  596.   int c,d=0;
  597.   DText.FrontPen=GREENPEN;
  598.   if(pla==0) d++;
  599.   DText.IText=(UBYTE *) "POWER >";
  600.   PrintIText(ConPort,&DText,400L,8L*line);
  601.   DText.FrontPen=PLAYERPEN(d);
  602.   DText.IText=(UBYTE *)general.pname[d];
  603.   PrintIText(ConPort,&DText,456L,8L*line);
  604.   while(1)
  605.     {
  606.     c=cget(pla);
  607.     if(c>='a' && (c-'a')<PLAYERNO && (c-'a')!=pla)
  608.       {
  609.       d=c-'a';
  610.       c=0x0d;
  611.       }
  612.     if(c==',' && d>0)
  613.       {
  614.       d--;
  615.       if(d==pla)
  616.         {
  617.         if(d==0) d=1;
  618.         else d--;
  619.         }
  620.       }
  621.     if(c=='.' && d+1<PLAYERNO)
  622.       {
  623.       d++;
  624.       if(d==pla)
  625.         {
  626.         if(d==PLAYERNO-1) d--;
  627.         else d++;
  628.         }
  629.       }
  630.     SetAPen(ConPort,BLACKPEN);
  631.     RectFill(ConPort,456L,line*8L,639L,line*8L+7L);
  632.     SetAPen(ConPort,GREENPEN);
  633.     DText.FrontPen=PLAYERPEN(d);
  634.     DText.IText=(UBYTE *)general.pname[d];
  635.     PrintIText(ConPort,&DText,456L,8L*line);
  636.     if(c==0x0d)
  637.       {
  638.       DText.FrontPen=GREENPEN;
  639.       return(d);
  640.       }
  641.     }
  642.   }
  643. cprint(pla,str1,str2,str3,str4,str5)
  644. int pla;
  645. char *str1;
  646. char *str2;
  647. char *str3;
  648. char *str4;
  649. char *str5;
  650.   {
  651.   if(!display_check(pla)) return();
  652.   SetAPen(ConPort,BLACKPEN);
  653.   RectFill(ConPort,400L,0L,639L,39L);
  654.   DText.FrontPen=GREENPEN;
  655.   DText.IText=(UBYTE *) str1;
  656.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,0L);
  657.   DText.IText=(UBYTE *) str2;
  658.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,8L);
  659.   DText.IText=(UBYTE *) str3;
  660.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,16L);
  661.   DText.IText=(UBYTE *) str4;
  662.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,24L);
  663.   DText.IText=(UBYTE *) str5;
  664.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,32L);
  665.   }
  666. nprint(pla,str)
  667. int pla;
  668. char *str;
  669.   {
  670.   int i;
  671.   if(!display_check(pla)) return();
  672.   DText.FrontPen=GREENPEN;
  673.   DText.IText=(UBYTE *)"                              ";
  674.   for(i=0;str[i]!='\0';i++) DText.IText[i]=(UBYTE) str[i];
  675.   for(;i<30;i++) DText.IText[i]=(UBYTE) ' ';
  676.   PrintIText(ConPort,&DText,400L,32L);
  677.   }
  678. randomize()
  679.   {
  680.   ULONG Seconds,Micros;
  681.   CurrentTime(&Seconds,&Micros);
  682.   srand((int)(Seconds+Micros));
  683.   }
  684. cget(pla)
  685. int pla;
  686.   {
  687.   long Code,Class,X,Y;
  688.   while(1)
  689.     {
  690.     WaitPort(ConWindow->UserPort);
  691.     mes=(struct IntuiMessage *) GetMsg(ConWindow->UserPort);
  692.     Class=mes->Class;
  693.     Code=mes->Code;
  694.     X=mes->MouseX;
  695.     Y=mes->MouseY;
  696.     ReplyMsg(mes);
  697.     if(Class==VANILLAKEY) return(Code);
  698.     if(Class==MOUSEBUTTONS && Code==SELECTDOWN) process_mouse(pla,(int) X/8,(int) Y/8);
  699.     if(Class==MOUSEBUTTONS && Code==MENUDOWN) showstatus(pla);
  700.     }
  701.   }
  702. coget()
  703.   {
  704.   long Code,Class;
  705.   while(1)
  706.     {
  707.     WaitPort(ConWindow->UserPort);
  708.     mes=(struct IntuiMessage *) GetMsg(ConWindow->UserPort);
  709.     Class=mes->Class;
  710.     Code=mes->Code;
  711.     ReplyMsg(mes);
  712.     if(Class==VANILLAKEY) return(Code);
  713.     }
  714.   }
  715. wait_space(pla)
  716.   {
  717.   if(!display_check(pla)) return();
  718.   DText.FrontPen=GREENPEN;
  719.   DText.IText=(UBYTE *) "    PRESS SPACE TO CONTINUE   ";
  720.   DText.DrawMode=JAM2 | INVERSVID;
  721.   PrintIText(ConPort,&DText,400L,32L);
  722.   while(coget()!=' ');
  723.   DText.DrawMode=JAM2;
  724.   DText.IText=(UBYTE *) "                              ";
  725.   PrintIText(ConPort,&DText,400L,32L);
  726.   }
  727. cinput(str,line)
  728. char *str;
  729. int line;
  730.   {
  731.   int pos,c;
  732.   DText.FrontPen=GREENPEN;
  733.   DText.IText=(UBYTE *)">                             ";
  734.   PrintIText(ConPort,&DText,400L,line*8L);
  735.   pos=0;
  736.   *str='\0';
  737.   while(pos<STRLENGTH-1)
  738.     {
  739.     SetAPen(ConPort,GREENPEN);
  740.     RectFill(ConPort,408L+pos*8,line*8L,415L+pos*8,line*8L+7);
  741.     c=coget();
  742.     SetAPen(ConPort,BLACKPEN);
  743.     RectFill(ConPort,408L+pos*8,line*8L,415L+pos*8,line*8L+7);
  744.     switch(c)
  745.       {
  746.       case '\b':if (pos) pos--;
  747.                 str[pos]='\0';
  748.                 DText.IText=(UBYTE *)" ";
  749.                 PrintIText(ConPort,&DText,408L+pos*8,line*8L);
  750.                 break;
  751.       case 0x0d:pos=STRLENGTH-1;break;
  752.       default  :str[pos]=c;
  753.                 pos++;
  754.                 str[pos]='\0';
  755.                 DText.IText=(UBYTE *)str;
  756.                 PrintIText(ConPort,&DText,408L,line*8L);
  757.       }
  758.     }
  759.   }
  760. mapdisplay(pla)
  761. int pla;
  762.   {
  763.   int sta,tas,i,j,c;
  764.   if(!display_check(pla)) return();
  765.   for(sta=0;sta<STARNO;sta++)
  766.     {
  767.     DText.IText=(UBYTE *)" ";
  768.     DText.IText[0]=(UBYTE) ('A'+sta);
  769.     c=CommData[pla].star[sta].ruler;
  770.     if(c<PLAYERNO) DText.FrontPen=PLAYERPEN(c);
  771.     if(c==FIGHTING) DText.FrontPen=OTHERPEN;
  772.     if(c==UNINHABITED || CommData[pla].star[sta].when<0) DText.FrontPen=WHITEPEN;
  773.     if(!knowstar(pla,sta) && CommData[pla].star[sta].when>=0) DText.DrawMode |= INVERSVID;
  774.                                                          else DText.DrawMode &=~INVERSVID;
  775.     PrintIText(ConPort,&DText,16L*star[sta].x,8L*star[sta].y);
  776.     DText.IText=(UBYTE *)" ";
  777.     DText.DrawMode=JAM2;
  778.     PrintIText(ConPort,&DText,16L*star[sta].x+8L,8L*star[sta].y);
  779.     if(!knowstar(pla,sta)) continue;
  780.     DText.IText=(UBYTE *)" ";
  781.     DText.DrawMode=JAM1;
  782.     for(i=0;i<PLAYERNO;i++)
  783.       {
  784.       DText.FrontPen=PLAYERPEN(i);
  785.       for(j=0;j<TASKNO;j++)
  786.         {
  787.         DText.IText[0]=(UBYTE) TASKCHAR(j);
  788.         if(task[i][j].headed==sta && task[i][j].arriving<=general.time)
  789.           PrintIText(ConPort,&DText,16L*star[sta].x+8L,8L*star[sta].y);
  790.         }
  791.       }
  792.     DText.DrawMode=JAM2;
  793.     }
  794.   DText.FrontPen=GREENPEN;
  795.   }
  796. starsummary(pla,sta)
  797. int pla;
  798. int sta;
  799.   {
  800.   int p,pla2,tas,sta2;
  801.   if(!display_check(pla)) return;
  802.   screen1=STARSUMMARY;show1=sta;
  803.   SetAPen(ConPort,BLACKPEN);
  804.   RectFill(ConPort,400L,40L,639L,119L);
  805.   if(sta<0 || sta>=STARNO) return();
  806.   if(sta!=sortsta) sortstars(sta);
  807.   pla2=CommData[pla].star[sta].ruler;
  808.   if(pla2<PLAYERNO)  DText.FrontPen=PLAYERPEN(pla2);
  809.   if(pla2==FIGHTING) DText.FrontPen=OTHERPEN;
  810.   if(CommData[pla].star[sta].when<0 ||pla2==UNINHABITED) DText.FrontPen=WHITEPEN;
  811.   DText.IText=(UBYTE *)"Star %(%%,%%)                 ";
  812.   *(DText.IText+5)=(UBYTE)'A'+sta;
  813.   rstr(star[sta].x,DText.IText+7);
  814.   rstr(star[sta].y,DText.IText+10);
  815.   DText.DrawMode |= INVERSVID;
  816.   PrintIText(ConPort,&DText,400L,40L);
  817.   DText.DrawMode &=~INVERSVID;
  818.   if(knowstar(pla,sta))
  819.     for(p=0;p<PLANETNO;p++)
  820.       {
  821.       if(star[sta].planet[p].size==0) continue;
  822.       if(star[sta].planet[p].mineable) DText.DrawMode=JAM2|INVERSVID;
  823.       if(star[sta].planet[p].ruler!=PLAYERNO) DText.FrontPen=PLAYERPEN(star[sta].planet[p].ruler);
  824.         else DText.FrontPen=WHITEPEN;
  825.       DText.IText=(UBYTE *)"%:%%%/%%%/%%%  ";
  826.       *(DText.IText+ 0)=(UBYTE)'0'+p;
  827.       mstr(star[sta].planet[p].size,DText.IText+2);
  828.       mstr(star[sta].planet[p].industrie,DText.IText+10);
  829.       *(DText.IText+13)=(UBYTE)' ';
  830.       if(star[sta].planet[p].population*star[sta].planet[p].industrie)
  831.         {
  832.         *(DText.IText+13)=(UBYTE) 'a'+star[sta].planet[p].producing;
  833.         if(star[sta].planet[p].producing==RESEARCHING)
  834.           *(DText.IText+13)=(UBYTE) 'R';
  835.         if(star[sta].planet[p].producing==INVESTING)
  836.           *(DText.IText+13)=(UBYTE) 'I';
  837.         if(star[sta].planet[p].producing==MINING)
  838.           *(DText.IText+13)=(UBYTE) 'M';
  839.         if(star[sta].planet[p].producing==DO_NOTHING)
  840.           *(DText.IText+13)=(UBYTE) ' ';
  841.         }
  842.       PrintIText(ConPort,&DText,400L+120*(p%2),48L+8*((int)p/2));
  843.       if(star[sta].planet[p].poptype!=PLAYERNO) DText.FrontPen=PLAYERPEN(star[sta].planet[p].poptype);
  844.         else DText.FrontPen=WHITEPEN;
  845.       DText.IText=(UBYTE *)"   ";
  846.       mstr(star[sta].planet[p].population,DText.IText);
  847.       PrintIText(ConPort,&DText,448L+120*(p%2),48L+8*((int)p/2));
  848.       DText.DrawMode=JAM2;
  849.       }
  850.   for(pla2=0;pla2<PLAYERNO;pla2 ++)
  851.     {
  852.     DText.DrawMode&=~INVERSVID;
  853.     DText.IText=(UBYTE *)"Tf";
  854.     DText.FrontPen=PLAYERPEN(pla2);
  855.     PrintIText(ConPort,&DText,400L,80L+8*pla2);
  856.     DText.IText=(UBYTE *) " ";
  857.     for(tas=0;tas<TASKNO;tas++) if(task[pla2][tas].headed==sta)
  858.       {
  859.       *DText.IText=(UBYTE)TASKCHAR(tas);
  860.       if(task[pla2][tas].arriving>general.time) DText.DrawMode|= INVERSVID;
  861.                                           else DText.DrawMode&=~INVERSVID;
  862.       if((task[pla2][tas].arriving>general.time || !knowstar(pla,sta)) && pla2!=pla)
  863.         continue;
  864.       PrintIText(ConPort,&DText,424L+tas*8,80L+8*pla2);
  865.       }
  866.     }
  867.   DText.IText=(UBYTE *) "%  ";
  868.   if(pla!=PLAYERNO) for(sta2=1;sta2<8;sta2++)
  869.     {
  870.     DText.IText[0]=(UBYTE) 'A'+sort[sta2];
  871.     tstr(dis[sta2],DText.IText+1);
  872.     pla2=CommData[pla].star[sort[sta2]].ruler;
  873.     if(pla2<PLAYERNO)  DText.FrontPen=PLAYERPEN(pla2);
  874.     if(pla2==FIGHTING) DText.FrontPen=OTHERPEN;
  875.     if(CommData[pla].star[sort[sta2]].when<0 ||pla2==UNINHABITED) DText.FrontPen=WHITEPEN;
  876.     if(!knowstar(pla,sort[sta2]) && CommData[pla].star[sort[sta2]].when>=0) DText.DrawMode|=INVERSVID;
  877.                       else DText.DrawMode&=~INVERSVID;
  878.     PrintIText(ConPort,&DText,368L+sta2*32L,112L);
  879.     }
  880.   DText.FrontPen=GREENPEN;
  881.   DText.DrawMode=JAM2;
  882.   }
  883. tasksummary(pla1,pla,tas)
  884. int pla1;
  885. int pla;
  886. int tas;
  887.   {
  888.   int i,shi,line;
  889.   if(!display_check(pla1)) return();
  890.   SetAPen(ConPort,BLACKPEN);
  891.   RectFill(ConPort,400L,120L,639L,199L);
  892.   if(task[pla][tas].headed==-1) return();
  893.   if(task[pla][tas].arriving>general.time||!knowstar(pla1,task[pla][tas].headed))
  894.     if(pla1!=pla) return();
  895.   screen2=TASKSUMMARY;showpla2=pla;show2=tas;
  896.   DText.FrontPen=PLAYERPEN(pla);
  897.   if(task[pla][tas].arriving<=general.time)
  898.     {
  899.     DText.IText=(UBYTE *)"Tf % at %    C:%%% S:%%% R:%%%";
  900.     }
  901.   else
  902.     {
  903.     DText.IText=(UBYTE *)"Tf % vs %/%% C:%%% S:%%% R:%%%";
  904.     *(DText.IText+10)=(UBYTE)'0'+((task[pla][tas].arriving-general.time)/10);
  905.     *(DText.IText+11)=(UBYTE)'0'+((task[pla][tas].arriving-general.time)%10);
  906.     }
  907.   if(tas<TASKNO) *(DText.IText+ 3)=(UBYTE) TASKCHAR(tas);
  908.     else *(DText.IText+ 3)=(UBYTE) '*';
  909.   *(DText.IText+ 8)=(UBYTE) 'A'+task[pla][tas].headed;
  910.   mstr(task_capa(pla,tas),DText.IText+15);
  911.   mstr(task_speed(pla,tas),DText.IText+21);
  912.   mstr(task_range(pla,tas),DText.IText+27);
  913.   DText.DrawMode |= INVERSVID;
  914.   PrintIText(ConPort,&DText,400L,120L);
  915.   DText.DrawMode &=~INVERSVID;
  916.   DText.FrontPen=WHITEPEN;
  917.   line=1;
  918.   for(shi=0;shi<SHIPNO;shi ++)
  919.     {
  920.     if(!task[pla][tas].ship_free[shi] && !task[pla][tas].ship_load[shi]) continue;
  921.     if(pla1!=pla && !task[pla][tas].ship_free[shi]) continue;
  922.     if(line==10)
  923.       {
  924.       wait_space(pla1);
  925.       DText.FrontPen=WHITEPEN;
  926.       SetAPen(ConPort,BLACKPEN);
  927.       RectFill(ConPort,400L,128L,639L,199L);
  928.       line=1;
  929.       }
  930.     DText.IText=(UBYTE *)ship[shi].name;
  931.     PrintIText(ConPort,&DText,400L,120L+line*8);
  932.     if(pla1==pla)
  933.       {
  934.       DText.IText=(UBYTE *)"   /   ";
  935.       mstr(task[pla][tas].ship_free[shi],DText.IText);
  936.       mstr(task[pla][tas].ship_load[shi],DText.IText+4);
  937.       PrintIText(ConPort,&DText,584L,120L+line*8);
  938.       }
  939.     else
  940.       {
  941.       DText.IText=(UBYTE *)"   ";
  942.       mstr(task[pla][tas].ship_free[shi],DText.IText);
  943.       PrintIText(ConPort,&DText,616L,120L+line*8);
  944.       }
  945.     line++;
  946.     }
  947.   DText.FrontPen=GREENPEN;
  948.   }
  949. shipsummary(pla,shi)
  950. int pla;
  951. int shi;
  952.   {
  953.   if(!display_check(pla)) return();
  954.   screen2=SHIPSUMMARY;showpla2=pla;show2=shi;
  955.   SetAPen(ConPort,BLACKPEN);
  956.   RectFill(ConPort,400L,120L,639L,199L);
  957.   DText.FrontPen=WHITEPEN;
  958.   DText.DrawMode |= INVERSVID;
  959.   DText.IText=(UBYTE *)"                              ";
  960.   PrintIText(ConPort,&DText,400L,120L);
  961.   DText.IText=(UBYTE *)ship[shi].name;
  962.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,120L);
  963.   DText.DrawMode &=~INVERSVID;
  964.   DText.IText=(UBYTE *)"Size      :000 Capacity  :000";
  965.   mstr(ship[shi].size,DText.IText+11);
  966.   mstr(ship[shi].capacity,DText.IText+26);
  967.   PrintIText(ConPort,&DText,400L,128L);
  968.   DText.IText=(UBYTE *)"HyperSpeed:000 HyperRange:000";
  969.   mstr(ship[shi].hypspeed,DText.IText+11);
  970.   mstr(ship[shi].hyprange,DText.IText+26);
  971.   PrintIText(ConPort,&DText,400L,136L);
  972.   DText.IText=(UBYTE *)"Attack    :000 No of At. :000";
  973.   mstr(ship[shi].attack,DText.IText+11);
  974.   mstr(ship[shi].attackno,DText.IText+26);
  975.   PrintIText(ConPort,&DText,400L,144L);
  976.   DText.IText=(UBYTE *)"Speed     :000 Shields   :000";
  977.   mstr(ship[shi].speed,DText.IText+11);
  978.   mstr(ship[shi].shields,DText.IText+26);
  979.   PrintIText(ConPort,&DText,400L,152L);
  980.   if(!(ship[shi].special&NOTPROD))
  981.     {
  982.     if(ship[shi].techlevel>general.techlevel[pla]) DText.DrawMode |= INVERSVID;
  983.     DText.IText=(UBYTE *)"Techcost  :000 Techlevel :000";
  984.     PrintIText(ConPort,&DText,400L,160L);
  985.     DText.IText=(UBYTE *)"   ";
  986.     mstr(ship[shi].techcost,DText.IText);
  987.     PrintIText(ConPort,&DText,488L,160L);
  988.     mstr(ship[shi].techlevel,DText.IText);
  989.     PrintIText(ConPort,&DText,608L,160L);
  990.     DText.DrawMode &=~INVERSVID;
  991.     }
  992.   DText.IText =(UBYTE *)"Starkill ";
  993.   if(ship[shi].special&STARKILLER) PrintIText(ConPort,&DText,400L,168L);
  994.   DText.IText =(UBYTE *)"One-Shot ";
  995.   if(ship[shi].special&KAMIKAZE) PrintIText(ConPort,&DText,480L,168L);
  996.   DText.IText =(UBYTE *)"Invisible";
  997.   if(ship[shi].special&INVISIBLE) PrintIText(ConPort,&DText,560L,168L);
  998.   DText.IText =(UBYTE *)"CataStart";
  999.   if(ship[shi].special&FASTEJECTABLE) PrintIText(ConPort,&DText,400L,176L);
  1000.   DText.IText =(UBYTE *)"Not build";
  1001.   if(ship[shi].special&NOTPROD) PrintIText(ConPort,&DText,480L,176L);
  1002.   DText.IText =(UBYTE *)"Theft    ";
  1003.   if(ship[shi].special&STEAL) PrintIText(ConPort,&DText,560L,176L);
  1004.   DText.IText =(UBYTE *)"Catapult ";
  1005.   if(ship[shi].special&FASTEJECTER) PrintIText(ConPort,&DText,400L,184L);
  1006.   DText.IText =(UBYTE *)"         ";
  1007.   if(ship[shi].special&NULL) PrintIText(ConPort,&DText,480L,184L);
  1008.   DText.IText =(UBYTE *)"         ";
  1009.   if(ship[shi].special&NULL) PrintIText(ConPort,&DText,560L,184L);
  1010.   DText.IText =(UBYTE *)"         ";
  1011.   if(ship[shi].special&NULL) PrintIText(ConPort,&DText,400L,192L);
  1012.   DText.IText =(UBYTE *)"         ";
  1013.   if(ship[shi].special&NULL) PrintIText(ConPort,&DText,480L,192L);
  1014.   DText.IText =(UBYTE *)"         ";
  1015.   if(ship[shi].special&NULL) PrintIText(ConPort,&DText,560L,192L);
  1016.   DText.FrontPen=GREENPEN;
  1017.   }
  1018. showstatus(pla)
  1019. int pla;
  1020.   {
  1021.   int i,s,p;
  1022.   if(!display_check(pla)) return();
  1023.   screen1=PLAYERSUMMARY;showpla1=pla;
  1024.   SetAPen(ConPort,BLACKPEN);
  1025.   RectFill(ConPort,400L,40L,639L,119L);
  1026.   DText.FrontPen=PLAYERPEN(pla);
  1027.   DText.DrawMode |= INVERSVID;
  1028.   DText.IText=(UBYTE *)"                              ";
  1029.   PrintIText(ConPort,&DText,400L,40L);
  1030.   DText.IText=(UBYTE *)"Year %%%%";
  1031.   qstr(general.time,DText.IText+5);
  1032.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,40L);
  1033.   DText.DrawMode &=~INVERSVID;
  1034.   DText.IText=(UBYTE *) general.pname[pla];
  1035.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,48L);
  1036.   DText.IText=(UBYTE *)"Pop:0000 Ind:0000 Tec:0000";
  1037.   qstr(population_no(pla),DText.IText+4);
  1038.   qstr(industrie_no(pla),DText.IText+13);
  1039.   qstr(general.techlevel[pla],DText.IText+22);
  1040.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,56L);
  1041.   for(i=0;i<PLAYERNO;i++)
  1042.     {
  1043.     if (i==pla) continue;
  1044.     DText.FrontPen=PLAYERPEN(i);
  1045.     DText.IText=(UBYTE *) general.pname[i];
  1046.     PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,48L+(i+(i<pla))*16);
  1047.     if (!exists(i))
  1048.       {
  1049.       DText.IText=(UBYTE *)"Killed";
  1050.       PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,(i+(i<pla))*16+56L);
  1051.       continue;
  1052.       }
  1053.     DText.IText=(UBYTE *)"--------/--------";
  1054.     pstr(general.relation[pla][i],DText.IText);
  1055.     pstr(general.relation[i][pla],DText.IText+9);
  1056.     PrintIText(ConPort,&DText,452L,(i+(i<pla))*16+56L);
  1057.     DText.IText=(UBYTE *)"%:0000";
  1058.     }
  1059.   DText.FrontPen=GREENPEN;
  1060.   }
  1061. mstr(no,str)
  1062. int no;
  1063. char *str;
  1064.   {
  1065.   if(no<0) return();
  1066.   if(no<1000)
  1067.     {
  1068.     str[0]='0'+(no/100)%10;
  1069.     str[1]='0'+(no/10)%10;
  1070.     str[2]='0'+no%10;
  1071.     return();
  1072.     }
  1073.   str[0]=' ';
  1074.   str[1]='o';
  1075.   str[2]='o';
  1076.   return();
  1077.   }
  1078. rstr(no,str)
  1079. int no;
  1080. char *str;
  1081.   {
  1082.   if(no<0) return;
  1083.   if(no<100)
  1084.     {
  1085.     str[0]='0'+(no/10)%10;
  1086.     str[1]='0'+no%10;
  1087.     return();
  1088.     }
  1089.   str[0]='o';
  1090.   str[1]='o';
  1091.   return();
  1092.   }
  1093. tstr(no,str)
  1094. int no;
  1095. char *str;
  1096.   {
  1097.   if(no<0) return();
  1098.   if(no<10)
  1099.     {
  1100.     str[0]='0'+no;
  1101.     str[1]=' ';
  1102.     return();
  1103.     }
  1104.   if(no<100)
  1105.     {
  1106.     str[0]='0'+(no/10)%10;
  1107.     str[1]='0'+no%10;
  1108.     return();
  1109.     }
  1110.   str[0]='o';
  1111.   str[1]='o';
  1112.   }
  1113. qstr(no,str)
  1114. int no;
  1115. char *str;
  1116.   {
  1117.   if(no<0) return;
  1118.   if(no<10000)
  1119.     {
  1120.     str[0]='0'+(no/1000)%10;
  1121.     str[1]='0'+(no/100)%10;
  1122.     str[2]='0'+(no/10)%10;
  1123.     str[3]='0'+no%10;
  1124.     return();
  1125.     }
  1126.   str[0]=' ';
  1127.   str[1]=' ';
  1128.   str[2]='o';
  1129.   str[3]='o';
  1130.   return();
  1131.   }
  1132. pstr(rel,str)
  1133. int rel;
  1134. char *str;
  1135.   {
  1136.   if(rel==WAR)
  1137.     {
  1138.     str[0]='W';
  1139.     str[1]='a';
  1140.     str[2]='r';
  1141.     str[3]=' ';
  1142.     str[4]=' ';
  1143.     str[5]=' ';
  1144.     str[6]=' ';
  1145.     str[7]=' ';
  1146.     return();
  1147.     }
  1148.   if(rel==PEACE)
  1149.     {
  1150.     str[0]='P';
  1151.     str[1]='e';
  1152.     str[2]='a';
  1153.     str[3]='c';
  1154.     str[4]='e';
  1155.     str[5]=' ';
  1156.     str[6]=' ';
  1157.     str[7]=' ';
  1158.     return();
  1159.     }
  1160.   if(rel==ALLIANCE)
  1161.     {
  1162.     str[0]='A';
  1163.     str[1]='l';
  1164.     str[2]='l';
  1165.     str[3]='i';
  1166.     str[4]='a';
  1167.     str[5]='n';
  1168.     str[6]='c';
  1169.     str[7]='e';
  1170.     return();
  1171.     }
  1172.   }
  1173. clearall(pla)
  1174. int pla;
  1175.   {
  1176.   register long i,j;
  1177.   if(!display_check(pla)) return();
  1178.   fline=0;
  1179.   SetRast(ConPort,BLACKPEN);
  1180.   SetAPen(ConPort,WHITEPEN);
  1181.   for(i=4;i<XMAX*16+4;i += 16)
  1182.     for(j=4;j<YMAX*8+4;j += 8)
  1183.       WritePixel(ConPort,i,j);
  1184.   screen1=CLEAR;
  1185.   screen2=CLEAR;
  1186.   }
  1187. showtasks(pla1,pla)
  1188. int pla1;
  1189. int pla;
  1190.   {
  1191.   int i;
  1192.   if(!display_check(pla1)) return();
  1193.   screen2=TASKOVERVIEW;showpla2=pla;
  1194.   SetAPen(ConPort,BLACKPEN);
  1195.   RectFill(ConPort,400L,120L,639L,199L);
  1196.   SetAPen(ConPort,PLAYERPEN(pla));
  1197.   RectFill(ConPort,400L,120L,639L,127L);
  1198.   DText.FrontPen=PLAYERPEN(pla);
  1199.   DText.DrawMode |= INVERSVID;
  1200.   DText.IText=(UBYTE *)"Taskforceoverview";
  1201.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,120L);
  1202.   DText.DrawMode &=~INVERSVID;
  1203.   DText.FrontPen=WHITEPEN;  
  1204.   DText.IText=(UBYTE *)"Tf % %/%%";
  1205.   for(i=0;i<TASKNO;i++)
  1206.     {
  1207.     if(task[pla][i].headed==-1) continue;
  1208.     if(pla1!=pla && (!knowstar(pla1,task[pla][i].headed) || task[pla][i].arriving>general.time) ) continue;
  1209.     DText.IText[3]=(UBYTE) TASKCHAR(i);
  1210.     DText.IText[5]=(UBYTE) 'A'+task[pla][i].headed;
  1211.     if(task[pla][i].arriving<=general.time)
  1212.       {
  1213.       DText.DrawMode&=~INVERSVID;
  1214.       DText.IText[6]=(UBYTE)' ';
  1215.       DText.IText[7]=(UBYTE)' ';
  1216.       DText.IText[8]=(UBYTE)' ';
  1217.       }
  1218.     else
  1219.       {
  1220.       DText.DrawMode|= INVERSVID;
  1221.       DText.IText[6]=(UBYTE)'/';
  1222.       rstr(task[pla][i].arriving-general.time,DText.IText+7);
  1223.       }
  1224.     PrintIText(ConPort,&DText,400L+80*(i/9),8*(i%9)+128L);
  1225.     }
  1226.   DText.DrawMode=JAM2;
  1227.   DText.FrontPen=GREENPEN;
  1228.   }
  1229. output_fight(pla,pla1,shi1,pla2,shi2,str)
  1230. int pla;
  1231. int pla1;
  1232. int shi1;
  1233. int pla2;
  1234. int shi2;
  1235. char *str;
  1236.   {
  1237.   long pos;
  1238.   if(!display_check(pla)) return();
  1239.   if(fline==25)
  1240.     {
  1241.     fline=0;
  1242.     wait_space(pla);
  1243.     }
  1244.   if (fline==0) 
  1245.     {
  1246.     SetAPen(ConPort,BLACKPEN);
  1247.     RectFill(ConPort,0L,0L,399L,199L);
  1248.     }
  1249.   pos=0;
  1250.   DText.FrontPen=PLAYERPEN(pla1);
  1251.   DText.IText=(UBYTE *)ship[shi1].name;
  1252.   PrintIText(ConPort,&DText,pos,fline*8L);
  1253.   pos+=IntuiTextLength(&DText);
  1254.   DText.FrontPen=WHITEPEN;
  1255.   DText.IText=(UBYTE *)" fires on ";
  1256.   PrintIText(ConPort,&DText,pos,fline*8L);
  1257.   pos+=IntuiTextLength(&DText);
  1258.   DText.FrontPen=PLAYERPEN(pla2);
  1259.   DText.IText=(UBYTE *)ship[shi2].name;
  1260.   PrintIText(ConPort,&DText,pos,fline*8L);
  1261.   pos+=IntuiTextLength(&DText);
  1262.   DText.FrontPen=WHITEPEN;
  1263.   DText.IText=(UBYTE *)":";
  1264.   PrintIText(ConPort,&DText,pos,fline*8L);
  1265.   pos+=IntuiTextLength(&DText);
  1266.   DText.IText=(UBYTE *)str;
  1267.   PrintIText(ConPort,&DText,pos,fline*8L);
  1268.   pos+=IntuiTextLength(&DText);
  1269.   DText.FrontPen=GREENPEN;
  1270.   fline++;
  1271.   }
  1272. tshipsummary(pla1,pla,shi)
  1273. int pla1;
  1274. int pla;
  1275. int shi;
  1276.   {
  1277.   int i;
  1278.   char name[30];
  1279.   if(!display_check(pla1)) return();
  1280.   screen2=SHIPOVERVIEW;showpla2=pla;show2=shi;
  1281.   SetAPen(ConPort,BLACKPEN);
  1282.   RectFill(ConPort,400L,120L,639L,199L);
  1283.   DText.FrontPen=PLAYERPEN(pla);
  1284.   DText.DrawMode |= INVERSVID;
  1285.   SetAPen(ConPort,PLAYERPEN(pla));
  1286.   RectFill(ConPort,400L,120L,639L,127L);
  1287.   strcpy(name,"Shipoverview:");
  1288.   strcat(name,ship[shi].name);
  1289.   DText.IText=(UBYTE *)name;
  1290.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,120L);
  1291.   DText.DrawMode &=~INVERSVID;
  1292.   DText.FrontPen=WHITEPEN;  
  1293.   if(pla!=pla1)
  1294.     {
  1295.     DText.IText=(UBYTE *)"Tf %  %%%";
  1296.     for(i=0;i<TASKNO;i++) 
  1297.       if(task[pla][i].headed!=-1 && task[pla][i].arriving<=general.time 
  1298.          && knowstar(pla1,task[pla][i].headed) && task[pla][i].ship_free[shi]>0)
  1299.       {
  1300.       if(task[pla][i].arriving>general.time) DText.DrawMode |= INVERSVID;
  1301.                                         else DText.DrawMode &=~INVERSVID;
  1302.       DText.IText[3]=(UBYTE)TASKCHAR(i);
  1303.       mstr(task[pla][i].ship_free[shi],DText.IText+6);
  1304.       PrintIText(ConPort,&DText,400L+80*(i/9),8*(i%9)+128L);
  1305.       }
  1306.     DText.FrontPen=GREENPEN;
  1307.     return();
  1308.     }
  1309.   DText.IText=(UBYTE *)"Tf% %%/%%";
  1310.   for(i=0;i<TASKNO;i++) 
  1311.     if(task[pla][i].headed!=-1 && INTASK(pla,i,shi))
  1312.     {
  1313.     if(task[pla][i].arriving>general.time) DText.DrawMode |= INVERSVID;
  1314.                                       else DText.DrawMode &=~INVERSVID;
  1315.     DText.IText[2]=(UBYTE)TASKCHAR(i);
  1316.     rstr(task[pla][i].ship_free[shi],DText.IText+4);
  1317.     rstr(task[pla][i].ship_load[shi],DText.IText+7);
  1318.     PrintIText(ConPort,&DText,400L+80*(i/9),8*(i%9)+128L);
  1319.     }
  1320.   DText.DrawMode=JAM2;
  1321.   DText.FrontPen=GREENPEN;
  1322.   }
  1323. showhelp(pla)
  1324. int pla;
  1325.   {
  1326.   if(!display_check(pla)) return();
  1327.   SetAPen(ConPort,BLACKPEN);
  1328.   RectFill(ConPort,400L,0L,639L,39L);
  1329.   DText.FrontPen=GREENPEN;
  1330.   DText.IText=(UBYTE *)"g=Go on        c=Carry Ships  ";
  1331.   PrintIText(ConPort,&DText,400L,0L);
  1332.   DText.IText=(UBYTE *)"h=Hyperspace   b=Build Ship   ";
  1333.   PrintIText(ConPort,&DText,400L,8L);
  1334.   DText.IText=(UBYTE *)"e=Emigrate     p=Possess Plan.";
  1335.   PrintIText(ConPort,&DText,400L,16L);
  1336.   DText.IText=(UBYTE *)"k=Kill         d=Declaration  ";
  1337.   PrintIText(ConPort,&DText,400L,24L);
  1338.   DText.IText=(UBYTE *)"j=join Tf l=Land Tf n=Split Tf";
  1339.   PrintIText(ConPort,&DText,400L,32L);
  1340.   }
  1341. showstars(pla)
  1342. int pla;
  1343.   {
  1344.   int i;
  1345.   if(!display_check(pla)) return();
  1346.   screen1=STAROVERVIEW;
  1347.   SetAPen(ConPort,BLACKPEN);
  1348.   RectFill(ConPort,400L,40L,639L,119L);
  1349.   SetAPen(ConPort,PLAYERPEN(pla));
  1350.   RectFill(ConPort,400L,40L,639L,47L);
  1351.   DText.FrontPen=PLAYERPEN(pla);
  1352.   DText.DrawMode |= INVERSVID;
  1353.   DText.IText=(UBYTE *)"Staroverview";
  1354.   PrintIText(ConPort,&DText,520L-IntuiTextLength(&DText)/2,40L);
  1355.   DText.DrawMode &=~INVERSVID;
  1356.   DText.FrontPen=WHITEPEN;  
  1357.   DText.IText=(UBYTE *)"% %%%/%%%/%%%";
  1358.   for(i=0;i<STARNO;i++)
  1359.     {
  1360.     if(CommData[pla].star[i].ruler==PLAYERNO) continue;
  1361.     if(CommData[pla].star[i].ruler<PLAYERNO) DText.FrontPen=PLAYERPEN(CommData[pla].star[i].ruler);
  1362.     if(CommData[pla].star[i].ruler==FIGHTING) DText.FrontPen=OTHERPEN;
  1363.     if(CommData[pla].star[i].ruler==UNINHABITED) DText.FrontPen=WHITEPEN;
  1364.     DText.DrawMode=JAM2;
  1365.     if(!knowstar(pla,i)) DText.DrawMode |= INVERSVID;
  1366.     DText.IText[0]= (UBYTE) ('A'+i);
  1367.     mstr(CommData[pla].star[i].totsize,DText.IText+2);
  1368.     mstr(CommData[pla].star[i].totpop,DText.IText+6);
  1369.     mstr(CommData[pla].star[i].totind,DText.IText+10);
  1370.     PrintIText(ConPort,&DText,400L+120*(i/(STARNO/2)),8*(i%(STARNO/2))+48L);
  1371.     }
  1372.   DText.DrawMode=JAM2;
  1373.   DText.FrontPen=GREENPEN;
  1374.   }
  1375. process_mouse(pla,x,y)
  1376. int pla;
  1377. int x;
  1378. int y;
  1379.   {
  1380.   int pla1,tas1,pla2,tas2,sta,shi1,shi2,shi3,p,i,j;
  1381.   /* Check star */
  1382.   for(sta=0;sta<STARNO;sta++) if(star[sta].y==y && star[sta].x*2==x)
  1383.     {
  1384.     starsummary(pla,sta);
  1385.     return();
  1386.     }
  1387.   /* Check for taskforce on main screen */
  1388.   for(sta=0;sta<STARNO;sta++) if(star[sta].y==y && star[sta].x*2+1==x) break;
  1389.   if(sta!=STARNO)
  1390.     {
  1391.     if(!knowstar(pla,sta))
  1392.       {
  1393.       starsummary(pla,sta);
  1394.       return();
  1395.       }
  1396.     pla2=-1;
  1397.     for(pla1=0;pla1<PLAYERNO;pla1++)
  1398.       for(tas1=0;tas1<TASKNO;tas1++)
  1399.         if(task[pla1][tas1].headed==sta && task[pla1][tas1].arriving<=general.time) pla2=pla1,tas2=tas1;
  1400.     if(pla2==-1)
  1401.       {
  1402.       starsummary(pla,sta);
  1403.       return();
  1404.       }
  1405.     for(pla1=0;pla1<PLAYERNO;pla1++)
  1406.       for(tas1=0;tas1<TASKNO;tas1++)
  1407.         if(task[pla1][tas1].headed==sta && task[pla1][tas1].arriving<=general.time && (pla1!=pla2 || tas1!=tas2))
  1408.           {
  1409.           starsummary(pla,sta);
  1410.           return();
  1411.           }
  1412.     tasksummary(pla,pla2,tas2);
  1413.     return();
  1414.     }
  1415.   /* Check for click on mapfield */
  1416.   if(x<50)
  1417.     {
  1418.     showstars(pla);
  1419.     return();
  1420.     }
  1421.   /* Check for planet in starsummary */
  1422.   if(screen1==STARSUMMARY && y>5 && y<10 && x>49)
  1423.     {
  1424.     p=(y-6)*2+(x>64);
  1425.     if(star[show1].planet[p].size>0)
  1426.       planetsummary(pla,show1,p);
  1427.     return();
  1428.     }
  1429.   /* Check for taskforce in starsummary */
  1430.   if(screen1==STARSUMMARY && x>52 && y>9 && y<14)
  1431.     {
  1432.     pla1=y-10;
  1433.     tas1=x-53;
  1434.     if(task[pla1][tas1].headed!=show1) return();
  1435.     tasksummary(pla,pla1,tas1);
  1436.     return();
  1437.     }
  1438.   /* Check for show all tasks in starsummary */
  1439.   if(screen1==STARSUMMARY && x<52 && y>9 && y<14)
  1440.     {
  1441.     pla1=y-10;
  1442.     showtasks(pla,pla1);
  1443.     return();
  1444.     }
  1445.   /* Check for star in starsummary */
  1446.   if(screen1==STARSUMMARY && x>49 && y==14)
  1447.     {
  1448.     sta=(x-50)/4+1;
  1449.     if (sta<8) starsummary(pla,sort[sta]);
  1450.     return();
  1451.     }
  1452.   /* Check for show shipsummary in tasksummary */
  1453.   if(screen2==TASKSUMMARY && x<70 && y>15)
  1454.     {
  1455.     shi2=0;
  1456.     for(shi1=0;shi1<SHIPNO;shi1++)
  1457.       if(task[showpla2][show2].ship_free[shi1]>0 ||
  1458.         (task[showpla2][show2].ship_load[shi1]>0 && pla==showpla2)) shi2++;
  1459.     shi3=((shi2-1)/10)*10+y-15;
  1460.     shi2=0;
  1461.     for(shi1=0;shi1<SHIPNO;shi1++)
  1462.       {
  1463.       if(task[showpla2][show2].ship_free[shi1]>0 ||
  1464.         (task[showpla2][show2].ship_load[shi1]>0 && pla==showpla2)) shi2++;
  1465.       if (shi3==shi2) break;
  1466.       }
  1467.     if(shi1==SHIPNO) return;
  1468.     shipsummary(pla,shi1);
  1469.     return();
  1470.     }
  1471.   /* Check for shipoverview */
  1472.   if(screen2==TASKSUMMARY && x>69 && y>15)
  1473.     {
  1474.     shi2=0;
  1475.     for(shi1=0;shi1<SHIPNO;shi1++)
  1476.       if(task[showpla2][show2].ship_free[shi1]>0 ||
  1477.         (task[showpla2][show2].ship_load[shi1]>0 && pla==showpla2)) shi2++;
  1478.     shi3=((shi2-1)/10)*10+y-15;
  1479.     shi2=0;
  1480.     for(shi1=0;shi1<SHIPNO;shi1++)
  1481.       {
  1482.       if(task[showpla2][show2].ship_free[shi1]>0 ||
  1483.         (task[showpla2][show2].ship_load[shi1]>0 && pla==showpla2)) shi2++;
  1484.       if (shi3==shi2) break;
  1485.       }
  1486.     if(shi1==SHIPNO) return;
  1487.     tshipsummary(pla,showpla2,shi1);
  1488.     return();
  1489.     }
  1490.   /* Check for click on shipname in planetsummary */
  1491.   if(screen2==PLANETSUMMARY && y==19)
  1492.     {
  1493.     if(star[show2].planet[showpla2].producing<SHIPNO)
  1494.       shipsummary(pla,star[show2].planet[showpla2].producing);
  1495.     return();
  1496.     }
  1497.   /* Check for click on Tf in Taskoverview */
  1498.   if(screen2==TASKOVERVIEW && y>15)
  1499.     {
  1500.     pla1=showpla2;
  1501.     tas1=((x-50)/10)*9+(y-16);
  1502.     tasksummary(pla,pla1,tas1);
  1503.     return();
  1504.     }
  1505.   /* Check for click on Tf in Shipoverview */
  1506.   if(screen2==SHIPOVERVIEW && y>15)
  1507.     {
  1508.     pla1=showpla2;
  1509.     tas1=((x-50)/10)*9+(y-16);
  1510.     if(task[pla1][tas1].ship_free[show2]==0 && pla1!=pla) return();
  1511.     if(!INTASK(pla1,tas1,show2)) return();
  1512.     tasksummary(pla,pla1,tas1);
  1513.     return();
  1514.     }
  1515.   if(screen1==STAROVERVIEW && y>5 && y<14)
  1516.     {
  1517.     sta=((x-50)/15)*8+(y-6);
  1518.     starsummary(pla,sta);
  1519.     return();
  1520.     }
  1521.   if(y<4) 
  1522.     {
  1523.     showhelp(pla);
  1524.     return();
  1525.     }
  1526.   }
  1527. planetsummary(pla1,sta,p)
  1528. int pla1;
  1529. int sta;
  1530. int p;
  1531.   {
  1532.   int pla2,cost;
  1533.   if(!display_check(pla1)) return();
  1534.   screen2=PLANETSUMMARY;
  1535.   show2=sta;
  1536.   showpla2=p;
  1537.   SetAPen(ConPort,BLACKPEN);
  1538.   RectFill(ConPort,400L,120L,639L,199L);
  1539.   if(sta<0 || sta>=STARNO) return();
  1540.   if(star[sta].planet[p].size<=0) return();
  1541.   if(!knowstar(pla1,sta)) return();
  1542.   pla2=star[sta].planet[p].ruler;
  1543.   if(pla2<PLAYERNO)  DText.FrontPen=PLAYERPEN(pla2);
  1544.   if(pla2==PLAYERNO) DText.FrontPen=WHITEPEN;
  1545.   SetAPen(ConPort,(long) DText.FrontPen);
  1546.   RectFill(ConPort,400L,120L,639L,127L);
  1547.   DText.DrawMode |= INVERSVID;
  1548.   DText.IText=(UBYTE *)"Star %(%%,%%)  Planet %       ";
  1549.   DText.IText[5]=(UBYTE) ('A'+sta);
  1550.   rstr(star[sta].x,DText.IText+7);
  1551.   rstr(star[sta].y,DText.IText+10);
  1552.   DText.IText[22]=(UBYTE) ('0'+p);
  1553.   PrintIText(ConPort,&DText,400L,120L);
  1554.   DText.DrawMode=JAM2;
  1555.   DText.FrontPen=WHITEPEN;
  1556.   DText.IText=(UBYTE *) "Size        :%%%";
  1557.   mstr(star[sta].planet[p].size,DText.IText+13);
  1558.   PrintIText(ConPort,&DText,400L,128L);
  1559.   DText.IText=(UBYTE *) "Population  :%%%";
  1560.   mstr(star[sta].planet[p].population,DText.IText+13);
  1561.   PrintIText(ConPort,&DText,400L,136L);
  1562.   DText.IText=(UBYTE *) "Industrie   :%%%";
  1563.   mstr(star[sta].planet[p].industrie,DText.IText+13);
  1564.   PrintIText(ConPort,&DText,400L,144L);
  1565.   DText.IText=(UBYTE *) "Building    :-";
  1566.   PrintIText(ConPort,&DText,400L,152L);
  1567.   if(star[sta].planet[p].producing<SHIPNO)
  1568.     {
  1569.     DText.IText=(UBYTE *) ship[star[sta].planet[p].producing].name;
  1570.     cost=ship[star[sta].planet[p].producing].techcost;
  1571.     }
  1572.   if(star[sta].planet[p].producing==MINING)
  1573.     {
  1574.     DText.IText=(UBYTE *) "MINING";
  1575.     cost=MCOST;
  1576.     }
  1577.   if(star[sta].planet[p].producing==INVESTING)
  1578.     {
  1579.     DText.IText=(UBYTE *) "INVESTING";
  1580.     cost=ICOST;
  1581.     }
  1582.   if(star[sta].planet[p].producing==RESEARCHING)
  1583.     {
  1584.     DText.IText=(UBYTE *) "RESEARCHING";
  1585.     cost=RCOST;
  1586.     }
  1587.   if(star[sta].planet[p].producing==DO_NOTHING)
  1588.     {
  1589.     DText.FrontPen=GREENPEN;
  1590.     return();
  1591.     }
  1592.   PrintIText(ConPort,&DText,504L,152L);
  1593.   DText.IText=(UBYTE *) "Cost        :%%% per Unit";
  1594.   mstr(cost,DText.IText+13);
  1595.   PrintIText(ConPort,&DText,400L,160L);
  1596.   DText.IText=(UBYTE *) "Average time:%%.%% Years";
  1597.   rstr(cost/star[sta].planet[p].industrie,DText.IText+13);
  1598.   rstr(((cost*100)/star[sta].planet[p].industrie)%100,DText.IText+16);
  1599.   PrintIText(ConPort,&DText,400L,168L);
  1600.   DText.IText=(UBYTE *) "Available   :Year %%%% (Est.)";
  1601.   cost =general.time+(cost-star[sta].planet[p].ipoints+star[sta].planet[p].industrie-1)/star[sta].planet[p].industrie;
  1602.   qstr(cost,DText.IText+18);
  1603.   PrintIText(ConPort,&DText,400L,176L);
  1604.   DText.FrontPen=GREENPEN;
  1605.   }
  1606. sortstars(sta)
  1607. int sta;
  1608.   {
  1609.   register i;
  1610.   int flag;
  1611.   sortsta=sta;
  1612.   for(i=0;i<STARNO;i++)
  1613.     {
  1614.     sort[i]=i;
  1615.     dis[i]=distance(sta,i);
  1616.     }
  1617.   flag=1;
  1618.   while(flag)
  1619.     {
  1620.     flag=0;
  1621.     for(i=0;i<STARNO-1;i++) if(dis[i]>dis[i+1])
  1622.       {
  1623.       flag=1;
  1624.       dis[i]   ^=dis[i+1];
  1625.       dis[i+1] ^=dis[i];
  1626.       dis[i]   ^=dis[i+1];
  1627.       sort[i]  ^=sort[i+1];
  1628.       sort[i+1]^=sort[i];
  1629.       sort[i]  ^=sort[i+1];
  1630.       /* Bet you didn't know that,did you ?                       */
  1631.       /* Exchanges sort[i] and sort[i+1], and dis[i] and dis[i+1] */
  1632.       /* Thanx for this algo,florian schwingenschloegel           */
  1633.       }
  1634.     }
  1635.   }
  1636.