home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d178 / cosmic.lha / Cosmic / con.c < prev    next >
C/C++ Source or Header  |  1989-02-04  |  38KB  |  1,286 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <fcntl.h>
  4. #include "defs.h"
  5.  
  6. extern struct NStar star[STARNO];
  7. extern struct NTask task[PLAYERNO][TASKNO+1];
  8. extern struct NCommData CommData[PLAYERNO];
  9. extern struct NGeneral general;
  10. extern int growth[PLANETNO];
  11. extern struct NShip ship[SHIPNO];
  12.  
  13. extern int fline;
  14. extern int mode,mode2,mode3;
  15. extern int file;
  16. extern int waittime;
  17.  
  18. conquest()
  19.   {
  20.   int pla,sta,x,y;
  21.   char *year="Year 0000";
  22.   init();
  23.   do
  24.     {
  25.     general.time++;
  26.     qstr(general.time,year+5);
  27.     cprint(PLAYERNO,"COSMIC CONQUEST",year,"Please wait","while fighting","");
  28.     for(sta=0;sta<STARNO;sta++)
  29.       {
  30.       update(sta);
  31.       if(fight(sta))
  32.         cprint(PLAYERNO,"COSMIC CONQUEST",year,"Please wait","while fighting","");
  33.       }
  34.     for(pla=0;pla<PLAYERNO;pla++)
  35.       {
  36.       cprint(PLAYERNO,"COSMIC CONQUEST",year,"It is the turn of",general.pname[pla],"");
  37.       wait_space(pla);
  38.       if(comp_cmp("klingon",general.pname[pla])) klingon(pla);
  39.       else 
  40.       if(comp_cmp("romulan",general.pname[pla])) romulan(pla);
  41.       else 
  42.       if(comp_cmp("alien",general.pname[pla])) alien(pla);
  43.       else 
  44.       if(comp_cmp("berserker",general.pname[pla])) berserker(pla);
  45.       else if(!comp_cmp("dead",general.pname[pla])) human(pla);
  46.       if (mode3)
  47.         {
  48.         x=mode2;mode2=0;y=mode3;mode3=0;
  49.         if (!display_check(pla) && exists(pla))
  50.           {
  51.           mode2=x;mode3=y;
  52.           human(pla);
  53.           }
  54.         else
  55.           {
  56.           mode2=x;
  57.           mode3=y;
  58.           }
  59.         }
  60.       clean_task(pla);
  61.       clearall(pla);
  62.       }
  63.     cprint(PLAYERNO,"COSMIC CONQUEST",year,"Please wait","while processing turn","");
  64.     process_turn();
  65.     }
  66.   while(playon());
  67.   deinit();
  68.   }
  69. load(str)
  70. char *str;
  71.   {
  72.   int pla,sta,tas;
  73.   char fname[STRLENGTH+10];
  74.   if(*str=='\0') cleanup("Bad filename");
  75.   strcpy(fname,"games/");
  76.   strcat(fname,str);
  77.   file=open(fname,O_RDONLY);
  78.   if(file==-1) return(0);
  79.   read(file,&general,sizeof(struct NGeneral));
  80.   for(sta=0;sta<STARNO;sta++) read(file,&star[sta],sizeof(struct NStar));
  81.   for(pla=0;pla<PLAYERNO;pla++)
  82.     for(tas=0;tas<TASKNO;tas++)
  83.       read(file,&task[pla][tas],sizeof(struct NTask));
  84.   for(pla=0;pla<PLAYERNO;pla++)
  85.     read(file,&CommData[pla],sizeof(struct NCommData));
  86.   close(file);file=-1;
  87.   return(1);
  88.   }
  89. save(str)
  90. char *str;
  91.   {
  92.   int pla,sta,tas;
  93.   char fname[STRLENGTH+10];
  94.   if(*str=='\0') cleanup("Bad filename");
  95.   strcpy(fname,"games/");
  96.   strcat(fname,str);
  97.   file=open(fname,O_WRONLY|O_CREAT);
  98.   if(file==-1) return(0);
  99.   write(file,&general,sizeof(struct NGeneral));
  100.   for(sta=0;sta<STARNO;sta++) write(file,&star[sta],sizeof(struct NStar));
  101.   for(pla=0;pla<PLAYERNO;pla++)
  102.     for(tas=0;tas<TASKNO;tas++)
  103.       write(file,&task[pla][tas],sizeof(struct NTask));
  104.   for(pla=0;pla<PLAYERNO;pla++)
  105.     write(file,&CommData[pla],sizeof(struct NCommData));
  106.   close(file);file=-1;
  107.   return(1);
  108.   }
  109. init()
  110.   {
  111.   int i,j,k,c;
  112.   char filename[STRLENGTH];
  113.   cprint(PLAYERNO,"COSMIC CONQUEST",VERSION,"by Carl Edman","(pd) Carl Edman","");
  114.   wait_space(PLAYERNO);
  115.   randomize();
  116.   cprint(PLAYERNO,"COSMIC CONQUEST","","Do you wish to ...","1.Start a new game  ","2.Restore an old one");
  117.   while((c=coget())<'1' || c>'2');
  118.   if(c=='1')
  119.     {
  120.     cprint(PLAYERNO,"COSMIC CONQUEST","","Please enter name of players","","");
  121.     for(i=0;i<PLAYERNO;i++)
  122.       {
  123.       cinput(general.pname[i],3);
  124.       for(j=0;j<i;j++) if(!strcmp(general.pname[j],general.pname[i])) break;
  125.       if (j<i || strlen(general.pname[i])==0) 
  126.         {
  127.         nprint(PLAYERNO,"Invalid name.");
  128.         i--;
  129.         }
  130.       else nprint(PLAYERNO,"OK.");
  131.       }
  132.     cprint(PLAYERNO,"COSMIC CONQUEST","","Please wait while","creating the galaxy","");
  133.     for(i=0;i<STARNO;i++) for(j=0;j<PLANETNO;j++)
  134.       {
  135.       star[i].planet[j].ruler=PLAYERNO;
  136.       star[i].planet[j].size=0;
  137.       star[i].planet[j].population=0;
  138.       star[i].planet[j].poptype=PLAYERNO;
  139.       star[i].planet[j].industrie=0;
  140.       star[i].planet[j].producing=DO_NOTHING;
  141.       star[i].planet[j].ipoints=0;
  142.       star[i].planet[j].mineable=0;
  143.       }
  144.     for(i=0;i<(11*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=10;
  145.     for(i=0;i<( 9*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=20;
  146.     for(i=0;i<( 7*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=40;
  147.     for(i=0;i<( 4*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=60;
  148.     for(i=0;i<( 3*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=120;
  149.     for(i=0;i<(10*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].mineable=1;
  150.     spread_stars();
  151.     while(spread_players()) spread_stars();
  152.     for(i=0;i<PLAYERNO;i++)
  153.       {
  154.       general.techlevel[i]=100;
  155.       for(j=0;j<PLAYERNO;j++) general.relation[i][j]=PEACE;
  156.       for(j=1;j<=TASKNO;j++)
  157.         {
  158.         task[i][j].headed=-1;
  159.         task[i][j].arriving=0;
  160.         for(k=0;k<SHIPNO;k++)
  161.           {
  162.           task[i][j].ship_free[k]=0;
  163.           task[i][j].ship_load[k]=0;
  164.           }
  165.         }
  166.       for(j=0;j<STARNO;j++)
  167.         {
  168.         CommData[i].star[j].ruler=PLAYERNO;
  169.         CommData[i].star[j].totsize=0;
  170.         CommData[i].star[j].totpop=0;
  171.         CommData[i].star[j].totind=0;
  172.         CommData[i].star[j].danger=100;
  173.         CommData[i].star[j].when=-1000;
  174.         }
  175.       if(comp_cmp("dead",general.pname[i]))
  176.         {
  177.         task[i][0].headed=-1;
  178.         continue;
  179.         }
  180.       star[task[i][0].headed].planet[3].size=60;
  181.       star[task[i][0].headed].planet[3].mineable=1;
  182.       star[task[i][0].headed].planet[3].population=60;
  183.       star[task[i][0].headed].planet[3].poptype=i;
  184.       star[task[i][0].headed].planet[3].industrie=60;
  185.       star[task[i][0].headed].planet[3].ruler=i;
  186.       star[task[i][0].headed].planet[3].producing=MINING;
  187.       star[task[i][0].headed].planet[4].size=40;
  188.       star[task[i][0].headed].planet[4].mineable=0;
  189.       task[i][0].headed=-1;
  190.       }
  191.     general.time=0;
  192.     }
  193.   else
  194.     {
  195.     cprint(PLAYERNO,"COSMIC CONQUEST","","Please enter name of game","","");
  196.     cinput(filename,3);
  197.     while(!load(filename))
  198.       {
  199.       nprint(PLAYERNO,"Error loading file.");
  200.       cinput(filename,3);
  201.       }
  202.     }
  203.   clearall(PLAYERNO);
  204.   }
  205. deinit()
  206.   {
  207.   int c;
  208.   char filename[STRLENGTH];
  209.   cprint(PLAYERNO,"COSMIC CONQUEST","","Do you wish to ...","1.Save the game and quit","2.Just quit             ");
  210.   while((c=coget())<'1' || c>'2');
  211.   if(c=='1')
  212.     {
  213.     cprint(PLAYERNO,"COSMIC CONQUEST","","Please enter name of game","","");
  214.     cinput(filename,3);
  215.     while(!save(filename))
  216.       {
  217.       cinput(filename,3);
  218.       nprint(PLAYERNO,"Error saving file.");
  219.       }
  220.     }
  221.   cprint(PLAYERNO,"COSMIC CONQUEST",VERSION,"by Carl Edman","(C) 1988","GOODBYE !");
  222.   wait_space(PLAYERNO);
  223.   }
  224. task_speed(pla,tas)
  225. int pla;
  226. int tas;
  227.   {
  228.   int shi,k=10000;
  229.   for(shi=0;shi<SHIPNO;shi++) if(task[pla][tas].ship_free[shi]) k=MIN(k,ship[shi].hypspeed);
  230.   return(k);
  231.   }
  232. task_range(pla,tas)
  233. int pla;
  234. int tas;
  235.   {
  236.   int shi,k=10000;
  237.   for(shi=0;shi<SHIPNO;shi++) if(task[pla][tas].ship_free[shi]) k=MIN(k,ship[shi].hyprange);
  238.   return(k);
  239.   }
  240. task_capa(pla,tas)
  241. int pla;
  242. int tas;
  243.   {
  244.   int shi,k=0;
  245.   for(shi=0;shi<SHIPNO;shi++)
  246.     k+=INTASK(pla,tas,shi)*ship[shi].capacity;
  247.   return(k);
  248.   }
  249. task_free(pla,tas)
  250. int pla;
  251. int tas;
  252.   {
  253.   int shi,k=0;
  254.   for(shi=0;shi<SHIPNO;shi++)
  255.     k+=task[pla][tas].ship_load[shi]*ship[shi].size;
  256.   return(task_capa(pla,tas)-k);
  257.   }
  258. task_size(pla,tas)
  259. int pla;
  260. int tas;
  261.   {
  262.   int shi,k=0;
  263.   for(shi=0;shi<SHIPNO;shi++)
  264.     k+=task[pla][tas].ship_free[shi]*ship[shi].size;
  265.   return(k);
  266.   }
  267. task_size_po(pla,tas)
  268. int pla;
  269. int tas;
  270.   {
  271.   int shi,k=0;
  272.   for(shi=0;shi<SHIPNO-2;shi++)
  273.     k+=task[pla][tas].ship_free[shi]*ship[shi].size;
  274.   return(k);
  275.   }
  276. knowstar(pla,sta)
  277. int pla;
  278. int sta;
  279.   {
  280.   int p;
  281.   if (mode==pla) return(1);
  282.   for(p=0;p<PLANETNO;p++)
  283.     if(star[sta].planet[p].ruler==pla || star[sta].planet[p].poptype==pla) return(1);
  284.   if(search_task(pla,sta)!=TASKNO) return(1);else return(0);
  285.   }
  286. headedstar(pla,sta)
  287. int pla;
  288. int sta;
  289.   {
  290.   int tas;
  291.   for(tas=0;tas<TASKNO;tas++) if(task[pla][tas].headed==sta) return(1);
  292.   return(0);
  293.   }
  294. controlstar(sta)
  295. int sta;
  296.   {
  297.   int p,pla;
  298.   for(p=0;p<PLANETNO;p++) if(star[sta].planet[p].ruler!=PLAYERNO) break;
  299.   if (p==PLANETNO) return(UNINHABITED);
  300.   pla=star[sta].planet[p].ruler;
  301.   for(p++;p<PLANETNO;p++) if(star[sta].planet[p].ruler!=PLAYERNO && star[sta].planet[p].ruler!=pla) break;
  302.   if(p!=PLANETNO) return(FIGHTING);
  303.   return(pla);
  304.   }
  305. rule_star(pl1,pl2)
  306. int pl1;
  307. int pl2;
  308.   {
  309.   int sta,p;
  310.   for(sta=0;sta<STARNO;sta++)
  311.     for(p=0;p<PLANETNO;p++) if(star[sta].planet[p].ruler==pl1 && star[sta].planet[p].poptype==pl2) return(1);
  312.   return(0);
  313.   }
  314. search_task(pla,sta)
  315. int pla;
  316. int sta;
  317.   {
  318.   int tas;
  319.   for(tas=0;tas<TASKNO;tas++) if(ATSTAR(pla,tas,sta)) return(tas);
  320.   return(TASKNO);
  321.   }
  322. clean_task(pla)
  323. int pla;
  324.   {
  325.   int tas,shi;
  326.   for(tas=0;tas<TASKNO;tas++)
  327.     {
  328.     if (task[pla][tas].headed==-1) continue;
  329.     for(shi=0;shi<SHIPNO;shi++)
  330.       if(task[pla][tas].ship_free[shi] || task[pla][tas].ship_load[shi]) break;
  331.     if(shi==SHIPNO)
  332.       {
  333.       task[pla][tas].headed=-1;
  334.       continue;
  335.       }
  336.     while(task_free(pla,tas)<0)
  337.       for(shi=0;shi<SHIPNO;shi++)
  338.         if(task[pla][tas].ship_load[shi]>0)
  339.           {
  340.           task[pla][tas].ship_load[shi]--;
  341.           task[pla][tas].ship_free[shi]++;
  342.           break;
  343.           }
  344.     }
  345.   }
  346. process_turn()
  347.   {
  348.   int sta,tas,p,gr,pla,pro;
  349.   for(sta=0;sta<STARNO;sta++) for(p=0;p<PLANETNO;p++) if(star[sta].planet[p].size)
  350.     {
  351.     if(star[sta].planet[p].population==0 || star[sta].planet[p].ruler==PLAYERNO)
  352.       {
  353.       star[sta].planet[p].poptype=PLAYERNO;
  354.       star[sta].planet[p].population=0;
  355.       star[sta].planet[p].industrie=0;
  356.       star[sta].planet[p].ruler=PLAYERNO;
  357.       star[sta].planet[p].producing=DO_NOTHING;
  358.       continue;
  359.       }
  360.     pla=star[sta].planet[p].ruler;
  361.     pro=star[sta].planet[p].producing;
  362.     gr=growth[p]-(4*star[sta].planet[p].population/star[sta].planet[p].size);
  363.     if(gr<0) gr=0;
  364.     gr *= (int)star[sta].planet[p].population;
  365.     if(RANDOM(100)<gr%100)
  366.       star[sta].planet[p].population+= gr/100+1;
  367.     else
  368.       star[sta].planet[p].population+= gr/100;
  369.     if(star[sta].planet[p].population>star[sta].planet[p].size)
  370.       {
  371.       if(star[sta].planet[p].poptype==pla)
  372.         {
  373.         tas=get_task(pla,sta);
  374.         if(tas!=-1)
  375.           set_ships_free(pla,tas,POPUNIT,
  376.                        (((int) star[sta].planet[p].population)-star[sta].planet[p].size)
  377.                        +task[pla][tas].ship_free[POPUNIT]);
  378.         }
  379.       star[sta].planet[p].population=star[sta].planet[p].size;
  380.       }
  381.     if(star[sta].planet[p].industrie>star[sta].planet[p].population) star[sta].planet[p].industrie=star[sta].planet[p].population;
  382.     star[sta].planet[p].ipoints += star[sta].planet[p].industrie;
  383.     switch(pro)
  384.       {
  385.       case INVESTING:
  386.           star[sta].planet[p].industrie+=star[sta].planet[p].ipoints/ICOST;
  387.           star[sta].planet[p].ipoints %= ICOST;
  388.           break;
  389.       case RESEARCHING:
  390.           general.techlevel[pla]+=(star[sta].planet[p].ipoints/RCOST)/(general.techlevel[pla]/100);
  391.           star[sta].planet[p].ipoints %= RCOST*(general.techlevel[pla]/100);
  392.           break;
  393.       case MINING:
  394.           tas=get_task(pla,sta);
  395.           if(tas!=-1)
  396.           set_ships_free(pla,tas,OREUNIT,
  397.                          ((int) task[pla][tas].ship_free[OREUNIT])+star[sta].planet[p].ipoints/MCOST);
  398.           star[sta].planet[p].ipoints %= MCOST;
  399.           break;
  400.       case DO_NOTHING:
  401.           star[sta].planet[p].ipoints=0;
  402.           break;
  403.       default:
  404.           tas=get_task(pla,sta);
  405.           if(tas!=-1)
  406.           set_ships_free(pla,tas,pro,
  407.                          ((int) task[pla][tas].ship_free[pro]) 
  408.                          +star[sta].planet[p].ipoints/ship[pro].techcost);
  409.           star[sta].planet[p].ipoints %= ship[pro].techcost;
  410.           break;
  411.       }
  412.     if(star[sta].planet[p].industrie<5) star[sta].planet[p].industrie++;
  413.     if(star[sta].planet[p].industrie>star[sta].planet[p].population) star[sta].planet[p].industrie=star[sta].planet[p].population;
  414.     }
  415.   }
  416. get_task(pla,sta)
  417. int pla;
  418. int sta;
  419.   {
  420.   int tas;
  421.   tas=search_task(pla,sta);
  422.   if (tas<TASKNO) return(tas);
  423.   return(make_task(pla,sta));
  424.   }
  425. make_task(pla,sta)
  426. int pla;
  427. int sta;
  428.   {
  429.   int tas,shi;
  430.   for(tas=0;tas<TASKNO;tas++) if(task[pla][tas].headed==-1) break;
  431.   if (tas==TASKNO) return(-1);
  432.   task[pla][tas].headed=sta;
  433.   task[pla][tas].arriving=general.time;
  434.   for(shi=0;shi<SHIPNO;shi++)
  435.     task[pla][tas].ship_free[shi]=task[pla][tas].ship_load[shi]=0;
  436.   return(tas);
  437.   }
  438. playon()
  439.   {
  440.   int c;
  441.   int p,pla,pla2;
  442.   if (waittime>general.time) return(1);
  443.   for(pla=0;pla<PLAYERNO;pla++) if(exists(pla)) break;
  444.   if (pla==PLAYERNO)
  445.     {
  446.     cprint(PLAYERNO,"COSMIC CONQUEST","GAME OVER","","No survivors","");
  447.     wait_space(PLAYERNO);
  448.     return(0);
  449.     }
  450.   for(pla2=pla+1;pla2<PLAYERNO;pla2++) if(exists(pla2)) break;
  451.   if(pla2==PLAYERNO)
  452.     {
  453.     cprint(PLAYERNO,"COSMIC CONQUEST","GAME OVER",general.pname[pla],"has won the galaxy","");
  454.     wait_space(PLAYERNO);
  455.     return(0);
  456.     }
  457.   cprint(PLAYERNO,"COSMIC CONQUEST","","Do you wish to ...","1.Play on","2.Quit   ");
  458.   while((c=coget())<'1' || c>'2') ;
  459.   return(c=='1');
  460.   }
  461. distance(sta1,sta2)
  462. int sta1;
  463. int sta2;
  464.   {
  465.   int r,q;
  466.   if(sta1<0 || sta1>=STARNO || sta2<0 || sta2>=STARNO) return(1000);
  467.   q =(star[sta1].x-star[sta2].x)*(star[sta1].x-star[sta2].x);
  468.   q+=(star[sta1].y-star[sta2].y)*(star[sta1].y-star[sta2].y);
  469.   for(r=0;r*r<q;r++);
  470.   return(r);
  471.   }
  472. do_command(pla,co)
  473. int pla;
  474. struct NCommand *co;
  475.   {
  476.   int i,j,k,l,sta,tas;
  477.   int c0,c1,c2,c3;
  478.   c0=co->par[0];
  479.   c1=co->par[1];
  480.   c2=co->par[2];
  481.   c3=co->par[3];
  482.   switch(co->com)
  483.     {
  484.     case DUMMY: /* DUMMY   */
  485.       if (mode2) printf("Pla %d:DUMMY\n",pla);
  486.       return(0);
  487.     case LAND:/* [0]=task [1]=planet */
  488.       if (mode2) printf("Pla %d:LAND Task %d Planet %d\n",pla,c0,c1);
  489.       if(task[pla][c0].headed==-1)
  490.         {
  491.         nprint(pla,"No such taskforce.");
  492.         return(-1);
  493.         }
  494.       if(task[pla][c0].arriving>general.time)
  495.         {
  496.         nprint(pla,"Taskforce in hyperspace.");
  497.         return(-1);
  498.         }
  499.       i=task[pla][c0].headed;
  500.       c2=MIN(INTASK(pla,c0,POPUNIT),star[i].planet[c1].size-star[i].planet[c1].population);
  501.       c3=MIN(INTASK(pla,c0,OREUNIT),star[i].planet[c1].population+c2-star[i].planet[c1].industrie);
  502.       if(star[i].planet[c1].size==0)
  503.         {
  504.         nprint(pla,"No such planet.");
  505.         return(-1);
  506.         }
  507.       if(star[i].planet[c1].ruler!=pla && star[i].planet[c1].ruler!=PLAYERNO && c2>0)
  508.         {
  509.         nprint(pla,"Planet under alien control.");
  510.         return(-1);
  511.         }
  512.       if(star[i].planet[c1].poptype!=pla && star[i].planet[c1].population>0 && star[i].planet[c1].poptype!=PLAYERNO && c2>0)
  513.         {
  514.         nprint(pla,"Alien population on planet.");
  515.         return(-1);
  516.         }
  517.       if(star[i].planet[c1].ruler!=pla && c2==0 && c3>0)
  518.         {
  519.         nprint(pla,"Planet not under control.");
  520.         return(-1);
  521.         }
  522.       if(star[i].planet[c1].population+c2==0 && c3>0)
  523.         {
  524.         nprint(pla,"No colony on planet.");
  525.         return(-1);
  526.         }
  527.       if(c2>0)
  528.         {
  529.         star[i].planet[c1].ruler=pla;
  530.         star[i].planet[c1].poptype=pla;
  531.         }
  532.       star[i].planet[c1].population += c2;
  533.       c2 = task[pla][c0].ship_free[POPUNIT]-c2;
  534.       set_ships_free(pla,c0,POPUNIT,c2);
  535.       if(c2<0)
  536.         set_ships_load(pla,c0,POPUNIT,((int) task[pla][c0].ship_load[POPUNIT])+c2);
  537.       star[i].planet[c1].industrie += c3;
  538.       c3 = task[pla][c0].ship_free[OREUNIT]-c3;
  539.       set_ships_free(pla,c0,OREUNIT,c3);
  540.       if(c3<0)
  541.         set_ships_load(pla,c0,OREUNIT,((int) task[pla][c0].ship_load[OREUNIT])+c3);
  542.       clean_task(pla);
  543.       update(i);
  544.       nprint(pla,"OK.");
  545.       return(1);
  546.     case CARRY:/* [0]=task [1]=ship of type 0........*/
  547.       if (mode2) printf("Pla %d:CARRY Task %d POPUNIT:%d OREUNIT:%d\n",pla,c0,co->par[POPUNIT+1],co->par[OREUNIT+1]);
  548.       if(task[pla][c0].headed==-1)
  549.         {
  550.         nprint(pla,"No such taskforce.");
  551.         return(-1);
  552.         }
  553.       if(task[pla][c0].arriving>general.time)
  554.         {
  555.         nprint(pla,"Taskforce in hyperspace.");
  556.         return(-1);
  557.         }
  558.       for(i=0;i<SHIPNO;i++) 
  559.         if (co->par[i+1]>INTASK(pla,c0,i))
  560.           break;
  561.       if(i!=SHIPNO)
  562.         {
  563.         nprint(pla,"Insufficient number of ships.");
  564.         return(-1);
  565.         }
  566.       for(i=0;i<SHIPNO;i++) if(co->par[i+1]!=task[pla][c0].ship_load[i]) break;
  567.       if(i==SHIPNO)
  568.         {
  569.         nprint(pla,"No change.");
  570.         return(1);
  571.         }
  572.       k=0;
  573.       for(i=0;i<SHIPNO;i++)
  574.         k+=INTASK(pla,c0,i)*ship[i].capacity-co->par[i+1]*ship[i].size;
  575.       if(k<0)
  576.         {
  577.         nprint(pla,"Insufficient capacity.");
  578.         return(-1);
  579.         }
  580.       for(i=0;i<SHIPNO;i++)
  581.         {
  582.         k=INTASK(pla,c0,i);
  583.         set_ships_load(pla,c0,i,co->par[i+1]);
  584.         set_ships_free(pla,c0,i,k-co->par[i+1]);
  585.         }
  586.       clean_task(pla);
  587.       nprint(pla,"OK.");
  588.       return(1);
  589.     case DESTINATION:/* [0]=task [1]=star */
  590.       if (mode2) printf("Pla %d:DESTINATION Task %d Star %d\n",pla,c0,c1);
  591.       if(task[pla][c0].headed==-1)
  592.         {
  593.         nprint(pla,"No such taskforce.");
  594.         return(-1);
  595.         }
  596.       if(task[pla][c0].arriving>general.time)
  597.         {
  598.         nprint(pla,"Taskforce in hyperspace.");
  599.         return(-1);
  600.         }
  601.       if(task[pla][c0].headed==c1)
  602.         {
  603.         nprint(pla,"Taskforce already at star.");
  604.         return(-1);
  605.         }
  606.       i=distance(task[pla][c0].headed,c1);
  607.       k=task_free(pla,c0);
  608.       for(j=0;j<SHIPNO;j++)
  609.         if(task[pla][c0].ship_free[j]>0 && ship[j].hyprange<i)
  610.           k-=task[pla][c0].ship_free[j]*ship[j].size;
  611.       if(k<0)
  612.         {
  613.         nprint(pla,"Distance to long.");
  614.         return(-1);
  615.         }
  616.       for(j=0;j<SHIPNO;j++) if(ship[j].hyprange<i)
  617.         {
  618.         set_ships_load(pla,c0,j,INTASK(pla,c0,j));
  619.         task[pla][c0].ship_free[j]=0;
  620.         }
  621.       k=task_free(pla,c0);
  622.       for(l=0;l<50;l++)
  623.         {
  624.         for(j=0;j<SHIPNO;j++) if(ship[j].hypspeed==l)
  625.           k -= task[pla][c0].ship_free[j]*ship[j].size;
  626.         if(k<0) break;
  627.         }
  628.       for(j=0;j<SHIPNO;j++) if(ship[j].hypspeed<l)
  629.         {
  630.         set_ships_load(pla,c0,j,INTASK(pla,c0,j));
  631.         task[pla][c0].ship_free[j]=0;
  632.         }
  633.       j=task_speed(pla,c0);
  634.       task[pla][c0].headed=c1;
  635.       task[pla][c0].arriving=general.time+ (i+j-1)/j;
  636.       nprint(pla,"OK.");
  637.       return(1);
  638.     case EMIGRATION:/* [0]=star [1]=planet [2]=amount */
  639.       if (mode2) printf("Pla %d:EMIGRATION Star %d Planet %d Amount %d\n",pla,c0,c1,c2);
  640.       if(star[c0].planet[c1].size==0)
  641.         {
  642.         nprint(pla,"No such planet.");
  643.         return(-1);
  644.         }
  645.       if(star[c0].planet[c1].ruler!=pla)
  646.         {
  647.         nprint(pla,"Planet not under control.");
  648.         return(-1);
  649.         }
  650.       if(star[c0].planet[c1].population==0)
  651.         {
  652.         nprint(pla,"Not inhabited.");
  653.         return(-1);
  654.         }
  655.       if(star[c0].planet[c1].poptype!=pla)
  656.         {
  657.         nprint(pla,"Alien population.");
  658.         return(-1);
  659.         }
  660.       if(star[c0].planet[c1].population<c2)
  661.         {
  662.         nprint(pla,"Population to small.");
  663.         return(-1);
  664.         }
  665.       i=get_task(pla,c0);
  666.       if(i==-1)
  667.         {
  668.         nprint(pla,"Too few Taskforces.");
  669.         return(-1);
  670.         }
  671.       set_ships_free(pla,i,POPUNIT,((int) task[pla][i].ship_free[POPUNIT])+c2);
  672.       star[c0].planet[c1].population -= c2;
  673.       if(star[c0].planet[c1].population==0)
  674.         {
  675.         star[c0].planet[c1].poptype=PLAYERNO;
  676.         star[c0].planet[c1].ruler=PLAYERNO;
  677.         }
  678.       if(star[c0].planet[c1].industrie>star[c0].planet[c1].population)
  679.         star[c0].planet[c1].industrie=star[c0].planet[c1].population;
  680.       update(c0);
  681.       nprint(pla,"OK.");
  682.       return(i);
  683.     case JOIN:/* [0]=task1 [1]=task2 ...*/
  684.       if (mode2) printf("Pla %d:JOIN Tasks %d %d %d %d\n",pla,c0,c1,c2,c3);
  685.       if(c0==TASKNO)
  686.         {
  687.         nprint(pla,"At least 1 taskforce to join.");
  688.         return(-1);
  689.         }
  690.       for(i=0;co->par[i]!=TASKNO;i++) if(task[pla][co->par[i]].headed==-1) break;
  691.       if(co->par[i]!=TASKNO)
  692.         {
  693.         nprint(pla,"No such taskforce.");
  694.         return(-1);
  695.         }
  696.       for(i=0;co->par[i]!=TASKNO;i++) if(task[pla][co->par[i]].arriving>general.time) break;
  697.       if(co->par[i]!=TASKNO)
  698.         {
  699.         nprint(pla,"Taskforce in hyperspace.");
  700.         return(-1);
  701.         }
  702.       j=task[pla][c0].headed;
  703.       for(i=0;co->par[i]!=TASKNO;i++) if(task[pla][co->par[i]].headed!=j) break;
  704.       if(co->par[i]!=TASKNO)
  705.         {
  706.         nprint(pla,"Taskforces not at same star.");
  707.         return(-1);
  708.         }
  709.       for(i=0;co->par[i]!=TASKNO;i++)
  710.         {
  711.         for(j=0;;j++) if(co->par[j]==TASKNO || (j!=i && co->par[i]==co->par[j])) break;
  712.         if(co->par[j]!=TASKNO) break;
  713.         }
  714.       if(co->par[i]!=TASKNO)
  715.         {
  716.         nprint(pla,"Can't selfjoin taskforce.");
  717.         return(-1);
  718.         }
  719.       for(i=1;co->par[i]!=TASKNO;i++)
  720.         {
  721.         for(j=0;j<SHIPNO;j++)
  722.           {
  723.           set_ships_free(pla,c0,j,((int) task[pla][c0].ship_free[j])+task[pla][co->par[i]].ship_free[j]);
  724.           set_ships_load(pla,c0,j,((int) task[pla][c0].ship_load[j])+task[pla][co->par[i]].ship_load[j]);
  725.           }
  726.         task[pla][co->par[i]].headed=-1;
  727.         }
  728.       nprint(pla,"OK.");
  729.       return(1);
  730.     case KILL:/* [0]=star [1]=planet*/
  731.       if (mode2) printf("Pla %d:KILL Star %d Planet %d\n",pla,c0,c1);
  732.       if(c1==PLANETNO)
  733.         {
  734.         j=SHIPNO;
  735.         for(i=0;i<TASKNO && j==SHIPNO;i++)
  736.           if(ATSTAR(pla,i,c0))
  737.             for(j=0;j<SHIPNO;j++)
  738.               if((ship[j].special&STARKILLER)&&task[pla][i].ship_free[j]) break;
  739.         if(i==TASKNO && j==SHIPNO)
  740.           {
  741.           nprint(pla,"No starkiller unloaded.");
  742.           return(-1);
  743.           }
  744.         for(i=0;i<PLAYERNO;i++)
  745.           for(j=0;j<TASKNO;j++) if(ATSTAR(i,j,c0)) task[i][j].headed=-1;
  746.         for(i=0;i<PLANETNO;i++)
  747.           {
  748.           star[c0].planet[i].size=0;
  749.           star[c0].planet[i].poptype=PLAYERNO;
  750.           star[c0].planet[i].population=0;
  751.           star[c0].planet[i].industrie=0;
  752.           star[c0].planet[i].ruler=PLAYERNO;
  753.           star[c0].planet[i].producing=DO_NOTHING;
  754.           }
  755.         update(c0);
  756.         return(1);
  757.         }
  758.       if(star[c0].planet[c1].size==0)
  759.         {
  760.         nprint(pla,"No such planet.");
  761.         return(-1);
  762.         }
  763.       if(star[c0].planet[c1].ruler!=pla)
  764.         {
  765.         nprint(pla,"Planet not under control.");
  766.         return(-1);
  767.         }
  768.       if(star[c0].planet[c1].population==0)
  769.         {
  770.         nprint(pla,"Not inhabited.");
  771.         return(-1);
  772.         }
  773.       if(star[c0].planet[c1].poptype==pla)
  774.         {
  775.         nprint(pla,"Own population.");
  776.         return(-1);
  777.         }
  778.       star[c0].planet[c1].poptype=PLAYERNO;
  779.       star[c0].planet[c1].population=0;
  780.       star[c0].planet[c1].industrie=0;
  781.       star[c0].planet[c1].ruler=PLAYERNO;
  782.       star[c0].planet[c1].producing=DO_NOTHING;
  783.       update(c0);
  784.       nprint(pla,"OK.");
  785.       return(1);
  786.     case SPLIT:/* [0]=task [1]=ship of type 0........*/
  787.       if (mode2) printf("Pla %d:SPLIT Task %d POPUNITS %d OREUNITS %d\n",pla,c0,co->par[POPUNIT+1],co->par[OREUNIT+1]);
  788.       if(task[pla][c0].headed==-1)
  789.         {
  790.         nprint(pla,"No such taskforce.");
  791.         return(-1);
  792.         }
  793.       if(task[pla][c0].arriving>general.time)
  794.         {
  795.         nprint(pla,"Taskforce in hyperspace.");
  796.         return(-1);
  797.         }
  798.       for(i=0;i<SHIPNO;i++) 
  799.         if (co->par[i+1]>INTASK(pla,c0,i))
  800.           break;
  801.       if(i!=SHIPNO)
  802.         {
  803.         nprint(pla,"Insufficient number of ships.");
  804.         return(-1);
  805.         }
  806.       for(i=0;i<SHIPNO;i++) if(co->par[i+1]!=0) break;
  807.       if(i==SHIPNO)
  808.         {
  809.         nprint(pla,"New taskforce without ships.");
  810.         return(-1);
  811.         }
  812.       for(i=0;i<SHIPNO;i++) if(co->par[i+1]!=INTASK(pla,c0,i)) break;
  813.       if(i==SHIPNO)
  814.         {
  815.         nprint(pla,"Old taskforce without ships.");
  816.         return(c0);
  817.         }
  818.       j=make_task(pla,task[pla][c0].headed);
  819.       if(j==-1)
  820.         {
  821.         nprint(pla,"To few taskforces.");
  822.         return(-1);
  823.         }
  824.       for(i=0;i<SHIPNO;i++)
  825.         {
  826.         k = task[pla][c0].ship_free[i] + task[pla][c0].ship_load[i];
  827.         task[pla][j].ship_free[i]=co->par[i+1];
  828.         k -= task[pla][j].ship_free[i];
  829.         task[pla][c0].ship_free[i] = MIN(k,250);
  830.         k -= task[pla][c0].ship_free[i];
  831.         task[pla][c0].ship_load[i] = k;
  832.         }
  833.       tas=task[pla][c0].headed;
  834.       clean_task(pla);
  835.       nprint(pla,"OK.");
  836.       return(j);
  837.     case PRODUCE:/* [0]=star [1]=planet [2]=what */
  838.       if (mode2) printf("Pla %d:PRODUCE Star %d Planet %d Product %d\n",pla,c0,c1,c2);
  839.       if(star[c0].planet[c1].size==0)
  840.         {
  841.         nprint(pla,"No such planet.");
  842.         return(-1);
  843.         }
  844.       if(star[c0].planet[c1].ruler!=pla)
  845.         {
  846.         nprint(pla,"Planet not under control.");
  847.         return(-1);
  848.         }
  849.       if(star[c0].planet[c1].industrie==0)
  850.         {
  851.         nprint(pla,"No production facilities.");
  852.         return(-1);
  853.         }
  854.       if(c2<SHIPNO && (ship[c2].special&NOTPROD))
  855.         {
  856.         nprint(pla,"Not producable.");
  857.         return(-1);
  858.         }
  859.       if(c2<SHIPNO && ship[c2].techlevel>general.techlevel[pla])
  860.         {
  861.         nprint(pla,"Techlevel too low.");
  862.         return(-1);
  863.         }
  864.       if(c2==MINING && !star[c0].planet[c1].mineable)
  865.         {
  866.         nprint(pla,"Planet not mineable.");
  867.         return(-1);
  868.         }
  869.       if(star[c0].planet[c1].producing!=c2)
  870.         star[sta].planet[c1].ipoints=MIN(star[sta].planet[c1].ipoints,star[sta].planet[c1].industrie-1);
  871.       star[c0].planet[c1].producing=c2;
  872.       nprint(pla,"OK.");
  873.       return(1);
  874.     case DECLARE:/* [0]=on whom [1]=what */
  875.       if (mode2) printf("Pla %d:DECLARE DecPla %d Status %d\n",pla,c0,c1);
  876.       if(c0==pla)
  877.         {
  878.         nprint(pla,"Impossible.");
  879.         return(-1);
  880.         }
  881.       general.relation[pla][c0]=c1;
  882.       nprint(pla,"OK.");
  883.       return(1);
  884.     case POSSESS:/* [0]=star [1]=planet */
  885.       if (mode2) printf("Pla %d:POSSESS Star %d Planet %d\n",pla,c0,c1);
  886.       if(search_att_task(pla,c0)==TASKNO)
  887.         {
  888.         nprint(pla,"No fighting taskforce at star.");
  889.         return(-1);
  890.         }
  891.       if(star[c0].planet[c1].size==0)
  892.         {
  893.         nprint(pla,"No such planet.");
  894.         return(-1);
  895.         }
  896.       if(star[c0].planet[c1].ruler==pla)
  897.         {
  898.         nprint(pla,"Planet already controlled.");
  899.         return(-1);
  900.         }
  901.       if(star[c0].planet[c1].population==0)
  902.         {
  903.         nprint(pla,"Planet uninhabited.");
  904.         return(-1);
  905.         }
  906.       for(i=0;i<PLAYERNO;i++) if (i!=pla && general.relation[i][pla]!=ALLIANCE && search_att_task(i,c0)!=TASKNO) break;
  907.       if(i!=PLAYERNO)
  908.         {
  909.         nprint(pla,"Other powers present.");
  910.         return(-1);
  911.         }
  912.       if(general.techlevel[star[c0].planet[c1].ruler]>general.techlevel[pla])
  913.         general.techlevel[pla]+=MIN(general.techlevel[star[c0].planet[c1].ruler]-general.techlevel[pla],star[c0].planet[c1].industrie/2);
  914.       star[c0].planet[c1].ruler=pla;
  915.       update(c0);
  916.       nprint(pla,"OK.");
  917.       return(1);
  918.     default   :;/*ERROR*/
  919.       if (mode2) printf("Pla %d:ERROR %d\n",pla,co->com);
  920.       return(-1);
  921.     }
  922.   }
  923. display_check(pla)
  924. int pla;
  925.   {
  926.   if(waittime>general.time) return(0);
  927.   if(pla==PLAYERNO || mode2 || mode3) return(1);
  928.   if(pla==-1) return(0);
  929.   if(comp_cmp("klingon",general.pname[pla])) return(0);
  930.   if(comp_cmp("romulan",general.pname[pla])) return(0);
  931.   if(comp_cmp("alien",general.pname[pla])) return(0);
  932.   if(comp_cmp("berserker",general.pname[pla])) return(0);
  933.   if(comp_cmp("dead",general.pname[pla])) return(0);
  934.   return(1);
  935.   }
  936. fight(sta)
  937. int sta;
  938.   {
  939.   int speed,tas,shi,pla1,pla2,i,j,disp;
  940.   char *c=" ";
  941.   for(pla1=0;pla1<PLAYERNO;pla1++)
  942.     {
  943.     if(search_att_task(pla1,sta)==TASKNO) continue;
  944.     for(pla2=0;pla2<PLAYERNO;pla2++)
  945.       if(search_task(pla2,sta)!=TASKNO && general.relation[pla1][pla2]==WAR) break;
  946.     if(pla2<PLAYERNO) break;
  947.     }
  948.   if(pla1==PLAYERNO) return(0);
  949.   for(pla2=0;pla2<PLAYERNO;pla2++)
  950.     {
  951.     if(!knowstar(pla2,sta)) continue;
  952.     if(display_check(pla2)) break;
  953.     }
  954.   if(pla2<PLAYERNO) disp=PLAYERNO;else disp=-1;
  955.   c[0]='A'+sta;
  956.   cprint(disp,"COSMIC CONQUEST","","Battle at Star",c,"");
  957.   starsummary(disp,sta);
  958.   for(pla1=0;pla1<PLAYERNO;pla1++)
  959.     {
  960.     task[pla1][TASKNO].headed=-1;
  961.     for(shi=0;shi<SHIPNO;shi++)
  962.       {
  963.       task[pla1][TASKNO].ship_free[shi]=0;
  964.       task[pla1][TASKNO].ship_load[shi]=0;
  965.       }
  966.     for(tas=0;tas<TASKNO;tas++)
  967.       if(ATSTAR(pla1,tas,sta))
  968.         {
  969.         for(shi=0;shi<SHIPNO;shi++)
  970.           {
  971.           set_ships_free(pla1,TASKNO,shi,((int) task[pla1][TASKNO].ship_free[shi])+task[pla1][tas].ship_free[shi]);
  972.           set_ships_load(pla1,TASKNO,shi,((int) task[pla1][TASKNO].ship_load[shi])+task[pla1][tas].ship_load[shi]);
  973.           } 
  974.         task[pla1][tas].headed=-1;
  975.         task[pla1][TASKNO].headed=sta;
  976.         task[pla1][TASKNO].arriving=0;
  977.         }
  978.     i=0;
  979.     for(shi=0;shi<SHIPNO;shi++) if(ship[shi].special&FASTEJECTER) i+=task[pla1][TASKNO].ship_free[shi]*ship[shi].capacity;
  980.     for(shi=0;shi<SHIPNO && i>0;shi++)
  981.       {
  982.       j=0;
  983.       if(ship[shi].special&FASTEJECTABLE) j=MIN(i/ship[shi].size,task[pla1][TASKNO].ship_load[shi]);
  984.       set_ships_free(pla1,TASKNO,shi,task[pla1][TASKNO].ship_free[shi]+j);
  985.       task[pla1][TASKNO].ship_load[shi] -= j;
  986.       i -= j*ship[shi].size;
  987.       }
  988.     if (task[pla1][TASKNO].headed!=-1)
  989.       {
  990.       tasksummary(disp,pla1,TASKNO);
  991.       wait_space(disp);
  992.       }
  993.     }
  994.   fight_now(disp);
  995.   for(pla1=0;pla1<PLAYERNO;pla1++)
  996.     if(popore_task(pla1,TASKNO))
  997.       {
  998.       i=0;
  999.       for(pla2=0;pla2<PLAYERNO;pla2++)
  1000.         if(att_task(pla2,TASKNO)&&general.relation[pla2][pla1]==WAR) i++;
  1001.       if(i==0) continue;
  1002.       i=INTASK(pla1,TASKNO,OREUNIT)/i;
  1003.       task[pla1][TASKNO].ship_free[POPUNIT]=task[pla1][TASKNO].ship_load[POPUNIT]=0;
  1004.       task[pla1][TASKNO].ship_free[OREUNIT]=task[pla1][TASKNO].ship_load[OREUNIT]=0;
  1005.       for(pla2=0;pla2<PLAYERNO;pla2++)
  1006.         if(att_task(pla2,TASKNO)&&general.relation[pla2][pla1]==WAR)
  1007.           set_ships_free(pla2,TASKNO,OREUNIT,task[pla2][TASKNO].ship_free[OREUNIT]+i);
  1008.       }
  1009.   for(pla1=0;pla1<PLAYERNO;pla1++)
  1010.     {
  1011.     tas=get_task(pla1,sta);
  1012.     if (tas==-1) continue;
  1013.     for(shi=0;shi<SHIPNO;shi++)
  1014.       {
  1015.       task[pla1][tas].ship_free[shi]=task[pla1][TASKNO].ship_free[shi];
  1016.       task[pla1][tas].ship_load[shi]=task[pla1][TASKNO].ship_load[shi];
  1017.       }
  1018.     clean_task(pla1);
  1019.     }
  1020.   wait_space(disp);
  1021.   clearall(disp);
  1022.   return(1);
  1023.   }
  1024. fight_now(disp)
  1025. int disp;
  1026.   {
  1027.   int cspeed,shi1,shi2,pla1,pla2,pla3,pl,x,ano,target,last;
  1028.   register int attack;
  1029.   int plashi[PLAYERNO];
  1030.   int platar[PLAYERNO];
  1031.   for(pla1=0;pla1<PLAYERNO;pla1++)
  1032.     {
  1033.     platar[pla1]=0;
  1034.     for(pla2=0;pla2<PLAYERNO;pla2++)
  1035.       if(general.relation[pla1][pla2]==WAR || general.relation[pla2][pla1]==WAR) platar[pla1]+=task_size_po(pla2,TASKNO);
  1036.     }
  1037.   for(cspeed=0;cspeed<MAXSPEED;cspeed++)
  1038.   for(shi1=0;shi1<SHIPNO;shi1++)
  1039.     {
  1040.     if(ship[shi1].attackno==0 || ship[shi1].speed!=cspeed) continue;
  1041.     pl=RANDOM(PLAYERNO);
  1042.     last=x;
  1043.     for(pla1=0;pla1<PLAYERNO;pla1++) plashi[pla1]=task[pla1][TASKNO].ship_free[shi1];
  1044.     for(x=pl;x<=last+PLAYERNO;x++)
  1045.       {
  1046.       pla1=x%PLAYERNO;
  1047.       if(plashi[pla1]!=0)
  1048.         {
  1049.         last=x;
  1050.         plashi[pla1]--;
  1051.         for(ano=0;ano<ship[shi1].attackno;ano++)
  1052.           {
  1053.           if(platar[pla1]<=0) continue;
  1054.           target=RANDOM(platar[pla1]);
  1055.           for(pla2=0;pla2<PLAYERNO;pla2++)
  1056.             {
  1057.             if(general.relation[pla1][pla2]!=WAR && general.relation[pla2][pla1]!=WAR) continue;
  1058.             for(shi2=0;shi2<SHIPNO-2;shi2++)
  1059.               {
  1060.               target -= task[pla2][TASKNO].ship_free[shi2]*ship[shi2].size;
  1061.               if(target<0) break;
  1062.               }
  1063.             if(shi2!=SHIPNO-2) break;
  1064.             }
  1065.           attack  = RSGN() * ship[shi1].attack;
  1066.           attack += RSGN() * ship[shi1].attack;
  1067.           attack += RSGN() * ship[shi1].attack;
  1068.           attack += RSGN() * ship[shi1].attack;
  1069.           attack = ship[shi1].attack+attack/4;
  1070.           if(attack<1)
  1071.             {
  1072.             output_fight(disp,pla1,shi1,pla2,shi2,"Miss");
  1073.             continue;
  1074.             }
  1075.           if(ship[shi2].shields>attack)
  1076.             {
  1077.             output_fight(disp,pla1,shi1,pla2,shi2,"Shields");
  1078.             continue;
  1079.             }
  1080.           output_fight(disp,pla1,shi1,pla2,shi2,"Destroyed");
  1081.           task[pla2][TASKNO].ship_free[shi2]--;
  1082.           if(ship[shi1].special&KAMIKAZE)
  1083.             {
  1084.             task[pla1][TASKNO].ship_free[shi1]--;
  1085.             for(pla3=0;pla3<PLAYERNO;pla3++)
  1086.               if(general.relation[pla3][pla1]==WAR || general.relation[pla1][pla3]==WAR) platar[pla3]-= ship[shi1].size;
  1087.             }
  1088.           for(pla3=0;pla3<PLAYERNO;pla3++)
  1089.             if(general.relation[pla3][pla2]==WAR || general.relation[pla2][pla3]==WAR) platar[pla3]-= ship[shi2].size;
  1090.           }
  1091.         }
  1092.       }
  1093.     }
  1094.   }
  1095. search_att_task(pla,sta)
  1096. int pla;
  1097. int sta;
  1098.   {
  1099.   int tas;
  1100.   for(tas=0;tas<TASKNO;tas++)
  1101.     if(ATSTAR(pla,tas,sta) && att_task(pla,tas)) return(tas);
  1102.   return(TASKNO);
  1103.   }
  1104. att_task(pla,tas)
  1105. int pla;
  1106. int tas;
  1107.   {
  1108.   int shi;
  1109.   if(task[pla][tas].headed==-1) return(0);
  1110.   for(shi=0;shi<SHIPNO-2;shi++) if(INTASK(pla,tas,shi) && ship[shi].attackno) return(1);
  1111.   return(0);
  1112.   }
  1113. popore_task(pla,tas)
  1114. int pla;
  1115. int tas;
  1116.   {
  1117.   int shi;
  1118.   for(shi=0;shi<SHIPNO-2;shi++) if(INTASK(pla,tas,shi)) return(0);
  1119.   return(1);
  1120.   }
  1121. exists(pla)
  1122. int pla;
  1123.   {
  1124.   int t,s,p;
  1125.   for(s=0;s<STARNO;s++) for(p=0;p<PLANETNO;p++)
  1126.     if(star[s].planet[p].poptype==pla && star[s].planet[p].ruler==pla && star[s].planet[p].population>0) return(1);
  1127.   for(t=0;t<TASKNO;t++) if(task[pla][t].headed!=-1 && INTASK(pla,t,POPUNIT)) return(1);
  1128.   return(0);
  1129.   }
  1130. population_no(pla)
  1131. int pla;
  1132.   {
  1133.   int i=0,s,p;
  1134.   for(s=0;s<STARNO;s++) for(p=0;p<PLANETNO;p++)
  1135.         if(star[s].planet[p].poptype==pla) i += star[s].planet[p].population;
  1136.   return(i);
  1137.   }
  1138. industrie_no(pla)
  1139. int pla;
  1140.   {
  1141.   int i=0,s,p;
  1142.   for(s=0;s<STARNO;s++) for(p=0;p<PLANETNO;p++) 
  1143.     if(star[s].planet[p].ruler==pla) 
  1144.       i += star[s].planet[p].industrie;
  1145.   return(i);
  1146.   }
  1147. nearstar(sta)
  1148. int sta;
  1149.   {
  1150.   int sta1=-1,dis,j;
  1151.   dis=1000;
  1152.   for(j=0;j<STARNO;j++) if(j!=sta && distance(sta,j)<dis) {sta1=j;dis=distance(sta,sta1);}
  1153.   return(sta1);
  1154.   }
  1155. set_ships_free(pla,tas,shi,no)
  1156. int pla;
  1157. int tas;
  1158. int shi;
  1159. int no;
  1160.   {
  1161.   if(no<0) no=0;
  1162.   if(no>250) no=250;
  1163.   task[pla][tas].ship_free[shi]=no;
  1164.   }
  1165. set_ships_load(pla,tas,shi,no)
  1166. int pla;
  1167. int tas;
  1168. int shi;
  1169. int no;
  1170.   {
  1171.   if(no<0) no=0;
  1172.   if(no>250) no=250;
  1173.   task[pla][tas].ship_load[shi]=(unsigned char) no;
  1174.   }
  1175. comp_cmp(name,str)
  1176. char *name;
  1177. char *str;
  1178.   {
  1179.   while(_tolower(*name)==_tolower(*str) && *name!='\0') {name++;str++;}
  1180.   if(*name=='\0') return(1);
  1181.   return(0);
  1182.   }
  1183. spread_stars()
  1184.   {
  1185.   int sta,sta2;
  1186.   for(sta=0;sta<STARNO;sta++)
  1187.     {
  1188.     star[sta].x=RANDOM(XMAX);
  1189.     star[sta].y=RANDOM(YMAX);
  1190.     for(sta2=0;sta2<sta;sta2++)
  1191.       if(star[sta2].x==star[sta].x && star[sta2].y==star[sta].y)
  1192.         {
  1193.         sta--;
  1194.         break;
  1195.         }
  1196.     }
  1197.   }
  1198. spread_players()
  1199.   {
  1200.   int i,j,k,l;
  1201.   for(i=0;i<PLAYERNO;i++)
  1202.     {
  1203.     task[i][0].headed=-1;
  1204.     for(l=0;l<100 && task[i][0].headed==-1;l++)
  1205.       {
  1206.       j=RANDOM(STARNO);
  1207.       if(distance(j,nearstar(j))>4) continue;
  1208.       for(k=0;k<i;k++) if(task[k][0].headed==j || distance(task[k][0].headed,j)<8) break;
  1209.       if(k==i) task[i][0].headed=j;
  1210.       }
  1211.     if(l==100) return(1);
  1212.     }
  1213.   return(0);
  1214.   }
  1215. update(sta)
  1216. int sta;
  1217.   {
  1218.   int p,pla,pla2,tas,ruler,totsize,totpop,totind;
  1219.   ruler=controlstar(sta);
  1220.   totsize=0;
  1221.   totpop=0;
  1222.   totind=0;
  1223.   for(p=0;p<PLANETNO;p++)
  1224.     {
  1225.     totsize+=star[sta].planet[p].size;
  1226.     totpop+=star[sta].planet[p].population;
  1227.     totind+=star[sta].planet[p].industrie;
  1228.     }
  1229.   for(pla=0;pla<PLAYERNO;pla++)
  1230.     {
  1231.     if(!knowstar(pla,sta)) continue;
  1232.     CommData[pla].star[sta].ruler=ruler;
  1233.     CommData[pla].star[sta].totsize=totsize;
  1234.     CommData[pla].star[sta].totpop=totpop;
  1235.     CommData[pla].star[sta].totind=totind;
  1236.     CommData[pla].star[sta].danger=danger(pla,sta);
  1237.     CommData[pla].star[sta].when=general.time;
  1238.     }
  1239.   }
  1240. danger(pla,sta)
  1241. int pla;
  1242. int sta;
  1243.   {
  1244.   int pl,danger;
  1245.   for(pl=0;pl<PLAYERNO;pl++)
  1246.     if(pl!=pla)
  1247.       switch(general.relation[pl][pla])
  1248.         {
  1249.         case PEACE:danger += fi_pres(pl,sta);
  1250.                    break;
  1251.         case WAR  :danger += fi_pres(pl,sta)*2;
  1252.                    break;
  1253.         case ALLIANCE:danger += fi_pres(pl,sta)/2;
  1254.                    break;
  1255.         }
  1256.   return(danger);
  1257.   }
  1258. fi_pres(pla,sta)
  1259. int pla;
  1260. int sta;
  1261.   {
  1262.   int pres,tas;
  1263.   pres=0;
  1264.   for(tas=0;tas<TASKNO;tas++) if(ATSTAR(pla,tas,sta)) pres+=fi_strength(pla,tas);
  1265.   return(pres);
  1266.   }
  1267. fi_strength(pla,tas)
  1268. int pla;
  1269. int tas;
  1270.   {
  1271.   int shi,str;
  1272.   str=0;
  1273.   for(shi=0;shi<SHIPNO;shi++) str+=task[pla][tas].ship_free[shi]*fi_value(shi);
  1274.   return(str);
  1275.   }
  1276. fi_value(shi)
  1277. int shi;
  1278.   {
  1279.   if(ship[shi].attack*ship[shi].attackno==0) return(0);
  1280.   return(ship[shi].attack*ship[shi].attackno+ship[shi].shields*ship[shi].shields/5);
  1281.   }
  1282. #include "klingon.c"
  1283. #include "berserker.c"
  1284. #include "alien.c"
  1285. #include "romulan.c"
  1286.