home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / conqsrc.lha / Conquest / src / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-03  |  8.5 KB  |  469 lines

  1. /* Display.c: Displaying all kinds of information */
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include "defs.h"
  5. #include "structs.h"
  6. #include "vars.h"
  7. #include "protos.h"
  8.  
  9. /* Display forces in tf battle. Return TRUE if any battle must happen */
  10. boolean display_forces(int ennum, int plnum, float *Enodds, float *Plodds)
  11. {
  12.   float enodds, plodds;
  13.   int en_forces = 0, pl_forces = 0;
  14.   
  15.   zero_tf(ENEMY,ennum);
  16.   zero_tf(player,plnum);
  17.  
  18.   if (tf[ENEMY][ennum].dest != 0)
  19.     en_forces = ((tf[ENEMY][ennum].c*c_guns + tf[ENEMY][ennum].b*b_guns)
  20.          * weapons[ENEMY]);
  21.  
  22.   if (tf[player][plnum].dest !=0)
  23.     pl_forces= ((tf[player][plnum].c*c_guns + tf[player][plnum].b*b_guns)
  24.         * weapons[player]);
  25.  
  26.   point(50,1);
  27.   if (tf[ENEMY][ennum].dest != 0)
  28.     print_star(tf[ENEMY][ennum].dest);
  29.   else if (tf[player][plnum].dest != 0)
  30.     print_star(tf[player][plnum].dest);
  31.  
  32.   clear_field();
  33.  
  34.   if (((en_forces == 0) && (pl_forces == 0)) ||
  35.       (tf[ENEMY][ennum].dest == 0) ||
  36.       (tf[player][plnum].dest == 0))
  37.     return(FALSE);
  38.  
  39.   enodds = ((float)pl_forces) / 
  40.     (en_forces + tf[ENEMY][ennum].t*t_def + tf[ENEMY][ennum].s*s_def);
  41.   enodds = fmin(14.0, enodds);
  42.   enodds = exp((log(0.8)) * enodds);
  43.  
  44.   plodds = ((float)en_forces) /
  45.      (pl_forces + tf[player][plnum].t*t_def  + tf[player][plnum].s*s_def);
  46.   plodds = fmin(14.0, plodds);
  47.   plodds = exp((log(0.8)) * plodds);
  48.   
  49.   point(1,19);
  50.   printf("enemy %5d", en_forces);
  51.   if (en_forces > 0)
  52.     printf("(weap %2d)", weapons[ENEMY]);
  53.   else
  54.     printf("         ");
  55.   printf("sur: %4.0f", enodds*100.0);
  56.   
  57.   point(1,20);
  58.   printf("player %5d", pl_forces);
  59.   if (pl_forces > 0)
  60.     printf("(weap %2d)", weapons[player]);
  61.   else
  62.     printf("         ");
  63.   printf("sur: %4.0f", plodds*100.0);
  64.  
  65.   *Enodds = enodds; 
  66.   *Plodds = plodds; 
  67.   return(TRUE);
  68. }
  69.  
  70. void disp_tf(struct sttf *taskf)
  71. {
  72.   if (taskf->t > 0) printf("%2dt", taskf->t);
  73.   else printf("   ");
  74.   if (taskf->s > 0) printf("%2ds", taskf->s);
  75.   else printf("   ");
  76.   if (taskf->c > 0) printf("%2dc", taskf->c);
  77.   else printf("   ");
  78.   if (taskf->b > 0) printf("%2db", taskf->b);
  79.   else printf("   ");
  80. }
  81.  
  82. void printmap()
  83. {
  84.   int i1, i2;
  85.  
  86.   clear_screen();
  87.  
  88.   for (i1 = BOARD_Y_SIZE ; i1 >= 1; i1--)
  89.   {
  90.     if ((i1 == 1) || (i1%5 == 0))
  91.       printf("%2d|", i1);
  92.     else
  93.       printf("  |");
  94.  
  95.     for (i2 = 1; i2 <= BOARD_X_SIZE; i2++)
  96.       printf("%c%c%c",board[i2][i1].enemy,board[i2][i1].star,
  97.          board[i2][i1].tf);
  98.     printf("|\n");
  99.   }
  100.  
  101.   printf("   ");
  102.   for (i1 = 1 ; i1 <= BOARD_X_SIZE; i1++ )
  103.     printf("---");
  104.   putchar('\n');
  105.  
  106.   printf("   ");
  107.   for (i1 = 1 ; i1<=bdsize; i1++)
  108.     if ((i1==1) || (i1%5 == 0))
  109.       printf("%2d ", i1);
  110.     else
  111.       printf("   ");
  112.   putchar('\n');
  113.  
  114.   point(33,18);
  115.   printf("Turn: %3d",turn);
  116.   point(33,19);
  117.   printf("Production yr: %d",production_year);
  118.  
  119.   bottom_field = 0;
  120.   for (i1 = 19; i1<=24; i1++)
  121.     left_line[i1] = false;
  122. }
  123.  
  124. void print_col()
  125. {
  126.   int i; 
  127.   tplanet *pplanet;
  128.  
  129.   printf("olonies:");
  130.   point(50,1);
  131.  
  132.   for (i= 1 ; i<=nstars; i++)
  133.   {
  134.     pplanet = stars[i].first_planet;
  135.     while (pplanet != nil) 
  136.     {
  137.       if (pplanet->team == player)
  138.       {
  139.     putchar(i+'A'-1);
  140.     if (((y_cursor > 21) && (x_cursor >= 50)) || (y_cursor > 24))
  141.     {
  142.       pause();
  143.       clear_field();
  144.       point(50,1);
  145.     }
  146.  
  147.     printf("%d:%2d                         ", pplanet->number, 
  148.            pplanet->psee_capacity);
  149.     point(x_cursor + 5, y_cursor);
  150.     x_cursor = x_cursor - 5;
  151.  
  152.     printf("(%2d,/%3d)", pplanet->inhabitants, pplanet->iu);
  153.     if (pplanet->conquered)
  154.       printf("Con");
  155.     else
  156.       printf("   ");
  157.     if (pplanet->mb != 0)
  158.       printf("%2dmb", pplanet->mb);
  159.     else
  160.       printf("    ");
  161.     if (pplanet->amb != 0)
  162.       printf("%2damb", pplanet->amb);
  163.     
  164.     point(x_cursor,y_cursor + 1);
  165.     
  166.       }
  167.       pplanet=pplanet->next;
  168.     }
  169.   }
  170.   clear_field();
  171.   clear_left();
  172. }
  173.  
  174. void starsum()
  175. {
  176.   char iline[81];  
  177.   int i,value;  
  178.   char strs;
  179.  
  180.   printf("tar summary:");
  181.   clear_left();
  182.   point(1,19);
  183.   putchar(':');
  184.   
  185.   get_line(iline);
  186.   strs = get_token(iline,&value);
  187.   point(50,1);
  188.  
  189.   if (strs == ' ') 
  190.     for (i = 1 ; i <= nstars; i++) print_star(i);
  191.   else 
  192.     do 
  193.     {
  194.       i = strs-'A'+1;
  195.       print_star(i);
  196.       strs = get_token(iline,&value);
  197.     } 
  198.     while (strs != ' ');
  199.  
  200.   clear_field();
  201. }
  202.  
  203. void tfsum()
  204. {
  205.   int i, value;  
  206.   char tfs;
  207.   char iline[81];  
  208.  
  209.   printf("f summary :");
  210.   get_line(iline);
  211.   tfs = get_token(iline,&value);
  212.   point(50,1);
  213.  
  214.   if (tfs==' ') 
  215.     for (i = 1 ; i<=26; i++) print_tf(i);
  216.   else 
  217.     do 
  218.     {
  219.       i = tfs - 'A' + 1;
  220.       print_tf(i);
  221.       tfs = get_token(iline,&value);
  222.     } 
  223.     while (tfs != ' ');
  224.  
  225.   clear_field();
  226.   clear_left();
  227. }
  228.  
  229. void clear_field()
  230. {
  231.   int new_bottom, y;
  232.  
  233.   new_bottom = y_cursor - 1;
  234.   if (new_bottom < bottom_field)
  235.   {
  236.     for (y = new_bottom + 1; y<=bottom_field; y++) 
  237.     {
  238.       point(50,y);
  239.       switch (terminal_type)
  240.       {
  241.        case adm3:
  242.     printf(blank_line);
  243.     break;
  244.        case vis400:
  245.        case vt52:
  246.     printf("\33[K");
  247.     break;
  248.       }
  249.     }
  250.   }
  251.  
  252.   bottom_field = new_bottom;
  253. }
  254.  
  255. void clear_left()
  256. {
  257.   int i;
  258.  
  259.   if (terminal_type != hardcopy) 
  260.     for (i = 19 ; i<=24; i++)
  261.       if (left_line[i]) 
  262.       {
  263.     switch (terminal_type)
  264.     {
  265.      case vt52:
  266.       point(1,i);
  267.       printf(blank_line);
  268.       break;
  269.     }
  270.     left_line[i] = false;
  271.       }
  272. }
  273.  
  274. void clear_screen()
  275. {
  276.   switch (terminal_type) 
  277.   {
  278.    case vis400:
  279.     printf("\33[2J");
  280.     break;
  281.    case vt52: 
  282.     printf("\33[H\33[J");
  283.     break;
  284.    case adm3: 
  285.     putchar('\32'); 
  286.     break;
  287.   }
  288.   point(1,1);
  289. }
  290.  
  291. void error(char *fmt, ...)
  292. {
  293.   va_list args;
  294.  
  295.   point(1,24);
  296.   va_start(args, fmt);
  297.   vprintf(fmt, args);
  298. }
  299.  
  300. void error_message()
  301. {
  302.   point(1,24);
  303. }
  304.  
  305. void print_tf(int i)
  306. {
  307.   int x, y;
  308.  
  309.   if ((i!=0) && (i<27)) 
  310.   {
  311.     if (tf[player][i].dest != 0) 
  312.     {
  313.       printf("TF%c:", i+'a'-1);
  314.  
  315.       x=tf[player][i].x; 
  316.       y=tf[player][i].y;
  317.       if (tf[player][i].eta==0)
  318.     putchar(tf[player][i].dest+'A'-1);
  319.       else
  320.     putchar(' ');
  321.       printf("(%2d,%2d)               ",x,y);
  322.  
  323.       point(x_cursor + 14, y_cursor);
  324.       x_cursor = x_cursor - 14;
  325.       disp_tf(&tf[player][i]);
  326.  
  327.       if (tf[player][i].eta != 0)
  328.       {
  329.     printf("%c2m", 0x9b); /* FOO? */
  330.     printf("%c%d", tf[player][i].dest+'A'-1, tf[player][i].eta);
  331.     printf("%c0m", 0x9b);
  332.       }
  333.       point(x_cursor, y_cursor+1);
  334.     }
  335.   }
  336. }
  337.  
  338. void print_star(int stnum)
  339. {
  340.   boolean see;
  341.   int i, x, y;
  342.   tplanet *p;
  343.   
  344.   if ((stnum != 0) && (stnum <= nstars)) 
  345.   {
  346.     /* FOO: A bit too long? */
  347.     if ((y_cursor+3+tf_stars[stnum][player]+tf_stars[stnum][ENEMY]) > 19) 
  348.     {
  349.       clear_field();
  350.       pause();
  351.       point(50,1);
  352.     }
  353.  
  354.     if (stars[stnum].visit[player] == true)
  355.     {
  356.       see = false;
  357.       printf("----- star %c -----            ", stnum+'A'-1);
  358.       point(50, y_cursor + 1);
  359.  
  360.       x = stars[stnum].x;
  361.       y = stars[stnum].y;
  362.  
  363.       /* Print taskforces */
  364.       if (tf_stars[stnum][player] != 0) 
  365.       {
  366.     see = true;
  367.     for (i=1; i<=26; i++)
  368.     {
  369.       if ((tf[player][i].dest == stnum) && (tf[player][i].eta == 0))
  370.       {
  371.         printf("TF%c                           ", i+'a'-1);
  372.         point(55,y_cursor);
  373.         disp_tf(&tf[player][i]);
  374.         point(50, y_cursor + 1);
  375.       }
  376.     }
  377.       }
  378.  
  379.       see |= (col_stars[stnum][player] != 0);
  380.  
  381.       if (see && (tf_stars[stnum][ENEMY] != 0))
  382.       {
  383.     for (i=1; ((tf[ENEMY][i].eta != 0) ||
  384.            (tf[ENEMY][i].dest != stnum)); i++)
  385.       ;
  386.  
  387.     printf(" EN:                          ");
  388.     point(55,y_cursor);
  389.     disp_tf(&tf[ENEMY][i]);
  390.     point( 50, y_cursor + 1);
  391.       }
  392.  
  393.       p = stars[stnum].first_planet;
  394.  
  395.       if (p == NULL) 
  396.       {
  397.     printf("  no useable planets          ");
  398.     point(50,y_cursor + 1);
  399.     return;
  400.       }
  401.  
  402.       for (;p != NULL; p=p->next, point(x_cursor, y_cursor + 1))
  403.       {
  404.     putchar(' ');
  405.     if (((y_cursor > 21) && (x_cursor >= 50)) ||
  406.         (y_cursor > 24))
  407.     {
  408.       pause();
  409.       clear_field();
  410.       point(50,1);
  411.     }
  412.  
  413.     printf("%d:%2d                         ", p->number, p->psee_capacity);
  414.     point(x_cursor + 5, y_cursor);
  415.     x_cursor = x_cursor - 5;
  416.  
  417.     if (p->psee_capacity == 0)
  418.     {
  419.       printf(" Decimated");
  420.       continue;
  421.     }
  422.     switch (p->team)
  423.     {
  424.      case none:
  425.       if (see)
  426.         printf(" No colony");
  427.       break;
  428.      case player:
  429.       printf("(%2d,/%3d)", p->inhabitants, p->iu);
  430.  
  431.       if (p->conquered)
  432.         printf("Con");
  433.       else
  434.         printf("   ");
  435.  
  436.       if (p->mb != 0)
  437.         printf("%2dmb", p->mb);
  438.       else
  439.         printf("    ");
  440.       if (p->amb!=0)
  441.         printf("%2damb", p->amb);
  442.       break;
  443.      case ENEMY:
  444.       if (see)
  445.       {
  446.         printf("*EN*");
  447.         if (p->conquered)
  448.         {
  449.           printf("Conquered");
  450.         } 
  451.         else
  452.           printf("   ");
  453.  
  454.         if (p->under_attack)
  455.         {
  456.           if (p->mb != 0)
  457.         printf("%2dmb", p->mb);
  458.           else
  459.         printf("    ");
  460.           if (p->amb != 0)
  461.         printf("%2damb", p->amb);
  462.         }
  463.       }
  464.     }
  465.       }
  466.     }
  467.   }
  468. }
  469.