home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume14 / xbattle / part04 / draw.c next >
C/C++ Source or Header  |  1993-01-27  |  43KB  |  1,327 lines

  1. #include <stdio.h>
  2.   
  3. /**** x include files ****/
  4. #include <X11/Xlib.h>
  5. #include <X11/Xutil.h>
  6. #include <X11/Xatom.h>
  7. #include <X11/keysym.h>
  8. #include <X11/keysymdef.h>
  9.  
  10. #include "extern.h"
  11.  
  12. /*************************************************************************/
  13. /**    drawboard                            **/
  14. /** draw the game board                            **/
  15. /**    Steve Lehar (slehar@park.bu.edu)                **/
  16. /**    Greg Lesher (lesher@park.bu.edu)                **/
  17. /*************************************************************************/
  18. drawboard(board, player,justboard)
  19.   square_type *board;
  20.   int player,
  21.       justboard;
  22. {
  23.   int i, j, k;
  24.  
  25.   if (winopen[player])
  26.   {
  27.     if (enable_hex)
  28.       XFillRectangle(xwindow[player]->display, xwindow[player]->window, xwindow[player]->hue[dark],
  29.                   0, 0, (boardsizex-1)*3*hex_halfside + 2*hex_side, boardsizey*2*hex_vert + hex_vert);
  30.  
  31.     /**** paint the pieces ****/
  32.     for (i=0; i<boardsizex; i++)
  33.     {
  34.       for (j=0; j<boardsizey; j++)
  35.       {
  36.         if (enable_hex)
  37.       blanksquare(xwindow[player],SQUARE(board,i,j),colorarray[player],
  38.                                          squaresize[colorarray[player]], TRUE);
  39.  
  40.         if (visible(board,colorarray[player],i,j))
  41.       drawsquare(xwindow[player],SQUARE(board,i,j),colorarray[player],
  42.                                          squaresize[colorarray[player]]);
  43.         else
  44.           drawblank(xwindow[player], i, j, SQUARE(board,i,j)->value[none],
  45.                           SQUARE(board,i,j)->seen[colorarray[player]],
  46.                           SQUARE(board,i,j)->growth, colorarray[player],
  47.                           squaresize[colorarray[player]], SQUARE(board,i,j));
  48.  
  49.         if (enable_storage && player == 0)
  50.           storedrawsquare(SQUARE(board,i,j), squaresize[0], TRUE);
  51.       }
  52.     }
  53.   }
  54.  
  55.   /**** write the text ****/
  56.  
  57.   if (!justboard)
  58.   {
  59.     for (i=0; i<nplayers; i++)
  60.     {
  61.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  62.                xwindow[i]->hue[0],
  63.                TEXTX,textyh[colorarray[i]][colorarray[i]],
  64.                blankline,strlen(blankline));
  65.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  66.                xwindow[i]->hue[0],
  67.                TEXTX,textyh[colorarray[i]][colorarray[i]],
  68.                messagestr,strlen(messagestr));
  69.     }
  70.   }
  71. }
  72.  
  73.  
  74. /*************************************************************************/
  75. /**    blanksquare                              **/
  76. /** Draw blank hexagon                            **/ 
  77. /**    Greg Lesher (lesher@cns.bu.edu)                    **/
  78. /*************************************************************************/
  79. blanksquare (xwindow, square, windowcolor, squaresize, flag)
  80.   xwindow_type *xwindow;
  81.   square_type *square;
  82.   int windowcolor,
  83.       squaresize,
  84.       flag;
  85. {
  86.   int  xpos, ypos;
  87.  
  88.   xpos = square->xpos;
  89.   ypos = square->ypos;
  90.  
  91.   hex_points[0].x = xpos - hex_halfside;
  92.   hex_points[0].y = ypos - hex_vert; 
  93.  
  94.   if (flag)
  95.     XFillPolygon(xwindow->display,xwindow->window,xwindow->hue[none],
  96.                                hex_points, 6, Convex, CoordModePrevious);
  97.   if (enable_grid[windowcolor])
  98.     XDrawLines(xwindow->display,xwindow->window,xwindow->hue[dark], hex_points, 7, CoordModePrevious);
  99. }
  100.  
  101.  
  102. /*************************************************************************/
  103. /**    drawmarch                              **/
  104. /** Draw passive march markers                        **/
  105. /**    Greg Lesher (lesher@park.bu.edu)                **/
  106. /*************************************************************************/
  107. drawmarch(board)
  108.   square_type *board;
  109. {
  110.   int x, y, k;
  111.  
  112.   for (x=0; x<boardsizex; x++)
  113.   {
  114.     for (y=0; y<boardsizey; y++)
  115.     {
  116.       if (SQUARE(board,x,y)->anymarch == ACTIVE)
  117.         drawmarcharrows (SQUARE(board,x,y),SQUARE(board,x,y)->marchcolor,ACTIVE);
  118.       else
  119.       {
  120.         for (k=0; k<nsides; k++)
  121.         {
  122.           if (SQUARE(board,x,y)->march[k] == PASSIVE)
  123.             if (SQUARE(board,x,y)->color == none)
  124.             {
  125.               drawmarcharrows(SQUARE(board,x,y),k,PASSIVE);
  126.             }
  127.             else if (!visible(board,k,x,y))
  128.               drawmarcharrows(SQUARE(board,x,y),k,PASSIVE);
  129.         }
  130.       }
  131.     }
  132.   }
  133. }
  134.  
  135.  
  136. /*************************************************************************/
  137. /**    drawmarcharrows                              **/
  138. /** Draw passive march markers                        **/
  139. /**    Greg Lesher (lesher@park.bu.edu)                **/
  140. /*************************************************************************/
  141. drawmarcharrows (square,marchcolor,type)
  142.   square_type *square;
  143.   int marchcolor,
  144.       type;
  145. {
  146.   int k,
  147.       xpos, ypos,
  148.       hafsquare;
  149.  
  150.   if (enable_hex)
  151.   {
  152.     xpos = square->xpos;
  153.     ypos = square->ypos;
  154.  
  155.     for (k=0; k<nplayers; k++)
  156.     {
  157.       if (colorarray[k] == marchcolor)
  158.       {
  159.         if(square->marchdir[marchcolor][HEX_UP])
  160.         {
  161.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  162.             xpos+2, ypos, xpos+2, ypos-hex_vert+2);
  163.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  164.             xpos+3, ypos, xpos+3, ypos-hex_vert+2);
  165.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  166.             xpos-2, ypos, xpos-2, ypos-hex_vert+2);
  167.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  168.             xpos-3, ypos, xpos-3, ypos-hex_vert+2);
  169.         }
  170.         if(square->marchdir[marchcolor][HEX_DOWN])
  171.         {
  172.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  173.             xpos+2, ypos, xpos+2, ypos+hex_vert-2);
  174.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  175.             xpos+3, ypos, xpos+3, ypos+hex_vert-2);
  176.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  177.             xpos-2, ypos, xpos-2, ypos+hex_vert-2);
  178.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  179.             xpos-3, ypos, xpos-3, ypos+hex_vert-2);
  180.         }
  181.         if(square->marchdir[marchcolor][HEX_RIGHT_UP])
  182.         {
  183.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  184.             xpos-2, ypos-2, xpos+hex_3quarterside-2, ypos-hex_halfvert-2);
  185.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  186.             xpos-3, ypos-3, xpos+hex_3quarterside-3, ypos-hex_halfvert-3);
  187.  
  188.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  189.             xpos+2, ypos+2, xpos+hex_3quarterside+2, ypos-hex_halfvert+2);
  190.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  191.             xpos+3, ypos+3, xpos+hex_3quarterside+3, ypos-hex_halfvert+3);
  192.         }
  193.         if(square->marchdir[marchcolor][HEX_RIGHT_DOWN])
  194.         {
  195.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  196.             xpos+2, ypos-2, xpos+hex_3quarterside+2, ypos+hex_halfvert-2);
  197.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  198.             xpos+3, ypos-3, xpos+hex_3quarterside+3, ypos+hex_halfvert-3);
  199.  
  200.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  201.             xpos-2, ypos+2, xpos+hex_3quarterside-2, ypos+hex_halfvert+2);
  202.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  203.             xpos-3, ypos+3, xpos+hex_3quarterside-3, ypos+hex_halfvert+3);
  204.         }
  205.         if(square->marchdir[marchcolor][HEX_LEFT_UP])
  206.         {
  207.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  208.             xpos+2, ypos-2, xpos-hex_3quarterside+2, ypos-hex_halfvert-2);
  209.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  210.             xpos+3, ypos-3, xpos-hex_3quarterside+3, ypos-hex_halfvert-3);
  211.  
  212.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  213.             xpos-2, ypos+2, xpos-hex_3quarterside-2, ypos-hex_halfvert+2);
  214.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  215.             xpos-3, ypos+3, xpos-hex_3quarterside-3, ypos-hex_halfvert+3);
  216.         }
  217.         if(square->marchdir[marchcolor][HEX_LEFT_DOWN])
  218.         {
  219.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  220.             xpos-2, ypos-2, xpos-hex_3quarterside-2, ypos+hex_halfvert-2);
  221.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  222.             xpos-3, ypos-3, xpos-hex_3quarterside-3, ypos+hex_halfvert-3);
  223.  
  224.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  225.             xpos+2, ypos+2, xpos-hex_3quarterside+2, ypos+hex_halfvert+2);
  226.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  227.             xpos+3, ypos+3, xpos-hex_3quarterside+3, ypos+hex_halfvert+3);
  228.         }
  229.   
  230.         if (type == PASSIVE)
  231.           XDrawRectangle(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  232.               xpos-DSIZE, ypos-DSIZE, 2*DSIZE, 2*DSIZE);
  233.       }
  234.     }
  235.   }
  236.   else
  237.   {
  238.     hafsquare=squaresize[marchcolor]/2;
  239.     xpos = square->x*squaresize[marchcolor]+hafsquare;
  240.     ypos = square->y*squaresize[marchcolor]+hafsquare;
  241.  
  242.     for (k=0; k<nplayers; k++)
  243.     {
  244.       if (colorarray[k] == marchcolor)
  245.       {
  246.         if(square->marchdir[marchcolor][UP])
  247.         {
  248.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  249.             xpos+2, ypos, xpos+2, ypos-hafsquare);
  250.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  251.             xpos+3, ypos, xpos+3, ypos-hafsquare);
  252.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  253.             xpos-2, ypos, xpos-2, ypos-hafsquare);
  254.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  255.             xpos-3, ypos, xpos-3, ypos-hafsquare);
  256.         }
  257.         if(square->marchdir[marchcolor][DOWN])
  258.         {
  259.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  260.             xpos+2, ypos, xpos+2, ypos+hafsquare-1);
  261.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  262.             xpos+3, ypos, xpos+3, ypos+hafsquare-1);
  263.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  264.             xpos-2, ypos, xpos-2, ypos+hafsquare-1);
  265.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  266.             xpos-3, ypos, xpos-3, ypos+hafsquare-1);
  267.         }
  268.         if(square->marchdir[marchcolor][RIGHT])
  269.         {
  270.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  271.             xpos, ypos+2, xpos+hafsquare-1, ypos+2);
  272.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  273.             xpos, ypos+3, xpos+hafsquare-1, ypos+3);
  274.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  275.             xpos, ypos-2, xpos+hafsquare-1, ypos-2);
  276.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  277.             xpos, ypos-3, xpos+hafsquare-1, ypos-3);
  278.         }
  279.         if(square->marchdir[marchcolor][LEFT])
  280.         {
  281.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  282.             xpos, ypos+2, xpos-hafsquare, ypos+2);
  283.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  284.             xpos, ypos+3, xpos-hafsquare, ypos+3);
  285.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  286.             xpos, ypos-2, xpos-hafsquare, ypos-2);
  287.           XDrawLine(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  288.             xpos, ypos-3, xpos-hafsquare, ypos-3);
  289.         }
  290.   
  291.         if (type == PASSIVE)
  292.           XDrawRectangle(xwindow[k]->display,xwindow[k]->window,xwindow[k]->hue[marchcolor],
  293.               xpos-DSIZE, ypos-DSIZE, 2*DSIZE, 2*DSIZE);
  294.       }
  295.     }
  296.   }
  297. }
  298.  
  299.  
  300. /*************************************************************************/
  301. /**    drawsquare                              **/
  302. /** Draw one square of the game board                    **/
  303. /**    Greg Lesher (lesher@park.bu.edu)                **/
  304. /*************************************************************************/
  305. drawsquare(xwindow,square,windowcolor,squaresize)
  306.   xwindow_type *xwindow;
  307.   square_type *square;
  308.   int windowcolor,
  309.       squaresize;
  310. {
  311.   int i, j, k,
  312.       offset,
  313.       ipos, jpos,
  314.       hafsquare, psize, bsize, hafpsize, psize1, hafpsize1,
  315.       value,
  316.       terrain_type,
  317.       max, smax, max_pos, smax_pos,
  318.       csize,hafc;
  319.   static GC onhue, offhue;
  320.  
  321.   hafsquare=squaresize/2;
  322.  
  323.   /**** get square coordinates ****/
  324.   i = square->x;
  325.   j = square->y;
  326.  
  327.   if (enable_hex)
  328.   {
  329.     ipos = square->xpos;
  330.     jpos = square->ypos;
  331.   }
  332.   else
  333.   {
  334.     ipos = i*squaresize;
  335.     jpos = j*squaresize;
  336.   }
  337.  
  338.   /**** set drawing color & value ****/
  339.  
  340.   if (square->color == none || square->color == FIGHT)
  341.     value=0;
  342.   else
  343.   {
  344.     onhue = xwindow->hue[square->color];
  345.     if ((xwindow->depth==1 && color2bw[sidemap[square->color]]<=GRAY3) ||
  346.         (xwindow->depth==8 && sidemap[square->color]==BLACK))
  347.       offhue = xwindow->hue[light];
  348.     else
  349.       offhue = xwindow->hue[dark];
  350.     value = square->value[square->color];
  351.   }
  352.  
  353.   if (square->color == none)
  354.   {
  355.     onhue = xwindow->hue[none];
  356.     offhue = xwindow->hue[dark];
  357.     value = 0;
  358.   }
  359.   
  360.   /**** compute piece size ****/
  361.  
  362.   if (enable_hex)
  363.     bsize = 11*hex_vert/6;
  364.   else
  365.     bsize = squaresize;
  366.   psize = (int)(bsize * areavalue[value]);
  367.   hafpsize = psize/2;
  368.  
  369.   /**** clear with appropriately colored square ****/
  370.  
  371.   if (enable_terrain)
  372.   {
  373.     terrain_type = square->value[none];
  374.  
  375.     if (enable_hex)
  376.     {
  377.       offset = -2 * square->value[none];
  378.  
  379.       if (terrain_type < 0)
  380.       {
  381.         double_copy (xwindow, square, windowcolor, squaresize, terrain_type, 0);
  382.         terrain_type = 0;
  383.       }
  384.       else
  385.         offset = 0;
  386.  
  387.       if (terrain_type == 1 && !enable_hills && !enable_forest)
  388.         XFillArc (xwindow->display,xwindow->window, xwindow->hue[none],
  389.            ipos-(hex_vert-1), jpos-(hex_vert-1), 2*(hex_vert-1), 2*(hex_vert-1), 0, 23040);
  390.       else
  391.         double_copy (xwindow, square, windowcolor, squaresize, terrain_type, offset);
  392.     }
  393.     else
  394.     {
  395.       offset = ((double)(-terrain_type) * squaresize)/(2*fillnumber);
  396.  
  397.       if (terrain_type < 0)
  398.         terrain_type = 0;
  399.       else
  400.         offset = 0;
  401.  
  402.       if (offset != 0)
  403.         XCopyArea (xwindow->display, xwindow->terrain[1], xwindow->window,
  404.                     xwindow->hue[dark], 0, 0, squaresize, squaresize, i*squaresize, j*squaresize);
  405.  
  406.       XCopyArea (xwindow->display, xwindow->terrain[terrain_type], xwindow->window,
  407.                           xwindow->hue[dark], 0, 0, squaresize-2*offset, squaresize-2*offset,
  408.                           i*squaresize+offset, j*squaresize+offset);
  409.     }
  410.   }
  411.   else
  412.   {
  413.     if (enable_hex)
  414.     {
  415.       XFillArc (xwindow->display,xwindow->window, xwindow->hue[none],
  416.            ipos-(hex_vert-1), jpos-(hex_vert-1), 2*(hex_vert-1), 2*(hex_vert-1), 0, 23040);
  417.  
  418. /**
  419.       blanksquare(xwindow, square, windowcolor, squaresize, TRUE);
  420. **/
  421.     }
  422.     else
  423.       XFillRectangle(xwindow->display,xwindow->window, xwindow->hue[none],
  424.            i*squaresize,j*squaresize, squaresize, squaresize);
  425.   }
  426.  
  427.   if (!enable_hex && enable_grid[windowcolor])
  428.   {
  429.      XDrawLine(xwindow->display,xwindow->window,xwindow->hue[dark],
  430.            ipos, jpos, ipos+squaresize, jpos);
  431.      XDrawLine(xwindow->display,xwindow->window,xwindow->hue[dark],
  432.            ipos, jpos, ipos, jpos+squaresize);
  433.   }
  434.  
  435.   
  436.   /**** singularly occupied square ****/
  437.   if (square->color != none && square->color != FIGHT)
  438.   {
  439.  
  440.     /**** draw center marker ****/
  441.     if (enable_hex)
  442.     {
  443.       XFillArc (xwindow->display,xwindow->window, onhue,
  444.                           ipos-hafpsize, jpos-hafpsize, psize, psize, 0, 23040);
  445.  
  446.       if (xwindow->drawletter[square->color])
  447.         XDrawString(xwindow->display,xwindow->window, xwindow->flip,
  448.                      ipos-xwindow->charwidth/2, jpos+xwindow->charheight/2,
  449.                      xwindow->letter[square->color], 1);
  450.     }
  451.     else
  452.     {
  453.       if (!xwindow->drawletter[square->color] && !enable_grid[windowcolor])
  454.           XDrawRectangle(xwindow->display,xwindow->window,xwindow->hue[dark],
  455.            ipos+hafsquare-CSIZE, jpos+hafsquare-CSIZE, 2*CSIZE, 2*CSIZE);
  456.  
  457.       XFillRectangle(xwindow->display,xwindow->window,onhue,
  458.            ipos+hafsquare-hafpsize, jpos+hafsquare-hafpsize, psize, psize);
  459.  
  460.       if (xwindow->drawletter[square->color])
  461.         XDrawString(xwindow->display,xwindow->window, xwindow->flip,
  462.                    ipos+squaresize/2-xwindow->charwidth/2, jpos+squaresize/2+xwindow->charheight/2,
  463.                    xwindow->letter[square->color], 1);
  464.     }
  465.  
  466.     /**** draw arrows ****/
  467.     if (enable_hidden[windowcolor])
  468.     {
  469.       if (square->color == windowcolor)
  470.       {
  471. #if SHOWFLOW
  472.         if (value == 0)
  473.           drawarrows(xwindow,square,onhue,offhue,i,j,hafpsize,squaresize,TRUE);
  474.         else
  475.           drawarrows(xwindow,square,onhue,offhue,i,j,hafpsize,squaresize,FALSE);
  476. #else
  477.         drawarrows(xwindow,square,onhue,offhue,i,j,hafpsize,squaresize,FALSE);
  478. #endif
  479.       }
  480.     }
  481.     else
  482.     {
  483. #if SHOWFLOW
  484.       if (value == 0)
  485.         drawarrows(xwindow,square,onhue,offhue,i,j,hafpsize,squaresize,TRUE);
  486.       else
  487.         drawarrows(xwindow,square,onhue,offhue,i,j,hafpsize,squaresize,FALSE);
  488. #else
  489.       drawarrows(xwindow,square,onhue,offhue,i,j,hafpsize,squaresize,FALSE);
  490. #endif
  491.     }
  492.   }
  493.   else if(square->color == FIGHT)       /**** draw fight square ****/
  494.   {
  495.     /**** find two largest components of square ****/
  496.     max = -1;
  497.     smax = -1; 
  498.     max_pos = 0;
  499.     for (k=0;k<nsides;k++)
  500.     {
  501.       if (square->value[k] > max)
  502.       {
  503.         smax = max; 
  504.         smax_pos = max_pos;
  505.         max = square->value[k];
  506.         max_pos = k;
  507.       }
  508.       else if (square->value[k] > smax)
  509.       {
  510.         smax = square->value[k];
  511.         smax_pos = k;
  512.       }
  513.     }
  514.     onhue = xwindow->hue[max_pos];
  515.     offhue = xwindow->hue[smax_pos];
  516.     psize = (int)(bsize * areavalue[square->value[max_pos]]);
  517.     hafpsize = psize/2;
  518.     psize1 = (int)(bsize * areavalue[square->value[smax_pos]]);
  519.     hafpsize1 = psize1/2;
  520.  
  521.     if (enable_hex)
  522.     {
  523.       XFillArc (xwindow->display,xwindow->window, onhue,
  524.            ipos-hafpsize, jpos-hafpsize, psize, psize, 0, 23040);
  525.       XFillArc (xwindow->display,xwindow->window, offhue,
  526.            ipos-hafpsize1, jpos-hafpsize1, psize1, psize1, 0, 23040);
  527.  
  528.       XDrawLine(xwindow->display, xwindow->window, onhue, ipos - hex_halfside, jpos - hex_halfvert,
  529.                   ipos + hex_halfside, jpos + hex_halfvert);
  530.       XDrawLine(xwindow->display, xwindow->window, onhue, ipos - hex_halfside, jpos + hex_halfvert,
  531.                   ipos + hex_halfside, jpos - hex_halfvert);
  532.     }
  533.     else
  534.     {
  535.       XFillRectangle(xwindow->display,xwindow->window,onhue,
  536.              ipos+hafsquare-hafpsize, jpos+hafsquare-hafpsize, psize, psize);
  537.       XFillRectangle(xwindow->display,xwindow->window,offhue,
  538.              ipos+hafsquare-hafpsize1, jpos+hafsquare-hafpsize1, psize1, psize1);
  539.  
  540.       /**** draw battle cross ****/
  541.       XDrawLine(xwindow->display,xwindow->window,onhue,
  542.                   ipos+2,jpos+2, ipos+squaresize-2,jpos+squaresize-2);
  543.       XDrawLine(xwindow->display,xwindow->window,onhue,
  544.                   ipos+squaresize-2,jpos+2, ipos+2,jpos+squaresize-2);
  545.     }
  546.   }
  547.  
  548.   /**** draw circle for town or base ****/
  549.   if(square->angle > 0)
  550.   {
  551.  
  552.     if (enable_hex)
  553.     {
  554.       if (square->angle < 23040)
  555.         csize = ((square->oldgrowth - 52)*7*hex_vert)/200;
  556.       else
  557.         csize = ((square->growth - 52)*7*hex_vert)/200;
  558.  
  559.       hafc = csize/2;
  560.  
  561.       XDrawArc(xwindow->display,xwindow->window,offhue,
  562.            ipos-hafc, jpos-hafc, csize, csize, 0, square->angle);
  563.  
  564.       XDrawArc(xwindow->display,xwindow->window,offhue,
  565.            ipos-hafc + 1, jpos-hafc + 1, csize - 2, csize - 2, 0, square->angle);
  566.     }
  567.     else
  568.     {
  569.       if (square->angle < 23040)
  570.         csize = ((square->oldgrowth - 52)*squaresize)/50;
  571.       else
  572.         csize = ((square->growth - 52)*squaresize)/50;
  573.  
  574.       hafc = (squaresize - csize)/2;
  575.  
  576.       XDrawArc(xwindow->display,xwindow->window,offhue,
  577.                ipos+hafc, jpos+hafc, csize, csize, 0, square->angle);
  578.  
  579.       XDrawArc(xwindow->display,xwindow->window,offhue,
  580.                ipos+hafc + 1, jpos+hafc + 1, csize - 2, csize - 2, 0, square->angle);
  581.     }
  582.   }
  583. }
  584.  
  585.  
  586. /*************************************************************************/
  587. /**    double_copy                              **/
  588. /** do flickerless pixmap copy for hexagonal board            **/ 
  589. /**    Greg Lesher (lesher@cns.bu.edu)                    **/
  590. /*************************************************************************/
  591. double_copy (xwindow, square, windowcolor, squaresize, terrain_type, offset)
  592.   xwindow_type *xwindow;
  593.   square_type *square;
  594.   int windowcolor,
  595.       squaresize,
  596.       terrain_type,
  597.       offset;
  598. {
  599.   if (terrain_type < 0)
  600.   {
  601.     if (enable_hills || enable_forest)
  602.     {
  603.       double_copy (xwindow, square, windowcolor, squaresize, 1, 0);
  604.       if (enable_grid[windowcolor])
  605.         blanksquare(xwindow, square, windowcolor, squaresize, FALSE);
  606.     }
  607.     else
  608.       blanksquare(xwindow, square, windowcolor, squaresize, TRUE);
  609.     return;
  610.   }
  611.  
  612.   XCopyArea (xwindow->display, xwindow->window, xwindow->terrain[terrain_type], xwindow->hue[light],
  613.                      square->xpos - hex_side, square->ypos - hex_vert, 2*hex_side, 2*hex_vert,
  614.                      0, 4*hex_vert);
  615.  
  616.   XCopyArea (xwindow->display, xwindow->terrain[terrain_type], xwindow->terrain[terrain_type],
  617.                      xwindow->gc_clear, offset*hex_side, 2*hex_vert, 2*hex_side, 2*hex_vert,
  618.                      0, 4*hex_vert);
  619.  
  620.   XCopyArea (xwindow->display, xwindow->terrain[terrain_type], xwindow->terrain[terrain_type],
  621.                      xwindow->gc_or, offset*hex_side, 0, 2*hex_side, 2*hex_vert,
  622.                      0, 4*hex_vert);
  623.  
  624.   XCopyArea (xwindow->display, xwindow->terrain[terrain_type], xwindow->window, xwindow->hue[light],
  625.                      0, 4*hex_vert, 2*hex_side, 2*hex_vert, square->xpos - hex_side,
  626.                      square->ypos - hex_vert);
  627.  
  628.   if (enable_grid[windowcolor])
  629.     blanksquare(xwindow, square, windowcolor, squaresize, FALSE);
  630. }
  631.  
  632.  
  633. /*************************************************************************/
  634. /**     drawarrows                                                      **/
  635. /**  Draws appropriate movement arrows                    **/
  636. /**     Greg Lesher (lesher@park.bu.edu)                                **/
  637. /*************************************************************************/
  638. drawarrows(xwindow,square,onhue,offhue,i,j,hafpsize, squaresize, halfsize)
  639.   xwindow_type *xwindow;
  640.   square_type *square;
  641.   GC onhue, offhue;
  642.   int i, j,
  643.       hafpsize,
  644.       squaresize,
  645.       halfsize;
  646. {
  647.   int ipos, jpos,
  648.       vert, horiz, halfvert,
  649.       hafsquare;
  650.  
  651.   if (enable_hex)
  652.   {
  653.     ipos = square->xpos;
  654.     jpos = square->ypos;
  655.  
  656.     vert = hex_vert;
  657.     halfvert = hex_halfvert;
  658.     horiz = hex_3quarterside;
  659.  
  660.     if (halfsize)
  661.     {
  662.       vert = vert/2;
  663.       halfvert = halfvert/2;
  664.       horiz = horiz/2;
  665.     }
  666.  
  667.     /**** draw direction arrows ****/
  668.     if(square->dir[HEX_UP])
  669.     {
  670.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos, ipos, jpos - vert + 2); 
  671.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos+1, jpos, ipos+1, jpos - vert + 2); 
  672.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos-1, jpos, ipos-1, jpos - vert + 2); 
  673.     }
  674.     if(square->dir[HEX_DOWN])
  675.     {
  676.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos, ipos, jpos + vert - 2); 
  677.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos+1, jpos, ipos+1, jpos + vert - 2); 
  678.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos-1, jpos, ipos-1, jpos + vert - 2); 
  679.     }
  680.     if(square->dir[HEX_RIGHT_UP])
  681.     {
  682.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos, ipos + horiz - 1,
  683.                                                 jpos - halfvert + 1); 
  684.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos+1, jpos, ipos+1 + horiz - 1,
  685.                                                 jpos - halfvert + 1); 
  686.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos-1, ipos+1 + horiz - 1,
  687.                                                 jpos-1 - halfvert + 1); 
  688.     }
  689.     if(square->dir[HEX_RIGHT_DOWN])
  690.     {
  691.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos, ipos + horiz - 1,
  692.                                                 jpos + halfvert - 1); 
  693.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos+1, jpos, ipos+1 + horiz - 1,
  694.                                                 jpos + halfvert - 1); 
  695.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos+1, ipos + horiz - 1,
  696.                                                 jpos+1 + halfvert - 1); 
  697.     }    
  698.     if(square->dir[HEX_LEFT_UP])
  699.     {
  700.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos, ipos - horiz + 1,
  701.                                                 jpos - halfvert + 1); 
  702.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos-1, jpos, ipos-1 - horiz + 1,
  703.                                                 jpos - halfvert + 1); 
  704.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos-1, ipos - horiz + 1,
  705.                                                 jpos-1 - halfvert + 1); 
  706.     }
  707.     if(square->dir[HEX_LEFT_DOWN])
  708.     {
  709.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos, ipos - horiz + 1,
  710.                                                 jpos + halfvert - 1); 
  711.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos-1, jpos, ipos-1 - horiz + 1,
  712.                                                 jpos + halfvert - 1); 
  713.       XDrawLine(xwindow->display,xwindow->window,onhue, ipos, jpos+1, ipos - horiz + 1,
  714.                                                 jpos+1 + halfvert - 1); 
  715.     }    
  716.   }
  717.   else
  718.   {
  719.     hafsquare=squaresize/2;
  720.  
  721.     ipos = i*squaresize+hafsquare;
  722.     jpos = j*squaresize+hafsquare;
  723.  
  724.     if (halfsize)
  725.       hafsquare /= 2;
  726.  
  727.     /**** draw direction arrows ****/
  728.     if(square->dir[UP])
  729.     {
  730.       XDrawLine(xwindow->display,xwindow->window,onhue,
  731.                   ipos-1, jpos, ipos-1, jpos-hafsquare);
  732. #if INVERT
  733.       XDrawLine(xwindow->display,xwindow->window,offhue,
  734.                   ipos, jpos, ipos, jpos-hafpsize);
  735.       XDrawLine(xwindow->display,xwindow->window,onhue,
  736.                   ipos, jpos-hafpsize, ipos, jpos-hafsquare);
  737. #else
  738.       XDrawLine(xwindow->display,xwindow->window,onhue,
  739.                   ipos, jpos, ipos, jpos-hafsquare);
  740. #endif
  741.       XDrawLine(xwindow->display,xwindow->window,onhue,
  742.                   ipos+1, jpos, ipos+1, jpos-hafsquare);
  743.     }
  744.     if(square->dir[DOWN])
  745.     {
  746.       XDrawLine(xwindow->display,xwindow->window,onhue,
  747.                   ipos-1, jpos, ipos-1, jpos+hafsquare-1);
  748. #if INVERT
  749.       XDrawLine(xwindow->display,xwindow->window,offhue,
  750.                   ipos, jpos, ipos, jpos+hafpsize);
  751.       XDrawLine(xwindow->display,xwindow->window,onhue,
  752.                   ipos, jpos+hafpsize, ipos, jpos+hafsquare-1);
  753. #else
  754.       XDrawLine(xwindow->display,xwindow->window,onhue,
  755.                   ipos, jpos, ipos, jpos+hafsquare-1);
  756. #endif
  757.       XDrawLine(xwindow->display,xwindow->window,onhue,
  758.                   ipos+1, jpos, ipos+1, jpos+hafsquare-1);
  759.     }
  760.     if(square->dir[RIGHT])
  761.     {
  762.       XDrawLine(xwindow->display,xwindow->window,onhue,
  763.                   ipos, jpos-1, ipos+hafsquare-1, jpos-1);
  764. #if INVERT
  765.       XDrawLine(xwindow->display,xwindow->window,offhue,
  766.                   ipos, jpos, ipos+hafpsize, jpos);
  767.       XDrawLine(xwindow->display,xwindow->window,onhue,
  768.                   ipos+hafpsize, jpos, ipos+hafsquare-1, jpos);
  769. #else
  770.       XDrawLine(xwindow->display,xwindow->window,onhue,
  771.                   ipos, jpos, ipos+hafsquare-1, jpos);
  772. #endif
  773.       XDrawLine(xwindow->display,xwindow->window,onhue,
  774.                   ipos, jpos+1, ipos+hafsquare-1, jpos+1);
  775.     }
  776.     if(square->dir[LEFT])
  777.     {
  778.       XDrawLine(xwindow->display,xwindow->window,onhue,
  779.                   ipos, jpos-1, ipos-hafsquare, jpos-1);
  780. #if INVERT
  781.       XDrawLine(xwindow->display,xwindow->window,offhue,
  782.                   ipos, jpos, ipos-hafpsize, jpos);
  783.       XDrawLine(xwindow->display,xwindow->window,onhue,
  784.                   ipos-hafpsize, jpos, ipos-hafsquare, jpos);
  785. #else
  786.       XDrawLine(xwindow->display,xwindow->window,onhue,
  787.                   ipos, jpos, ipos-hafsquare, jpos);
  788. #endif
  789.       XDrawLine(xwindow->display,xwindow->window,onhue,
  790.                   ipos, jpos+1, ipos-hafsquare, jpos+1);
  791.     }
  792.   }
  793. }
  794.  
  795.  
  796. /*************************************************************************/
  797. /**     drawblank                                                       **/
  798. /**  Draws a blank square                                               **/
  799. /**     Mark Lauer (elric@cs.su.oz.au)                                  **/
  800. /**     Greg Lesher (lesher@park.bu.edu)                                **/
  801. /*************************************************************************/
  802. drawblank (xwindow, i, j, terrain_type, seen, growth, windowcolor, squaresize, square)
  803.   xwindow_type *xwindow;
  804.   int i, j,
  805.       terrain_type,
  806.       seen,
  807.       growth,
  808.       windowcolor,
  809.       squaresize;
  810.   square_type *square;
  811. {
  812.   int csize, hafc,
  813.       ipos, jpos,
  814.       offset;
  815.  
  816.   if (enable_hex)
  817.   {
  818.     ipos = square->xpos;
  819.     jpos = square->ypos;
  820.   }
  821.   else
  822.   {
  823.     ipos = i*squaresize;
  824.     jpos = j*squaresize;
  825.   }
  826.  
  827.   /**** clear with appropriately colored square ****/
  828.   if (enable_terrain)
  829.   {
  830.     if (seen && !enable_localmap[windowcolor])
  831.     {
  832.       if (enable_hex)
  833.       {
  834.         offset = -2 * square->value[none];
  835.  
  836.         if (terrain_type < 0)
  837.         {
  838.           double_copy (xwindow, square, windowcolor, squaresize, terrain_type, 0);
  839.           terrain_type = 0;
  840.         }
  841.         else
  842.           offset = 0;
  843.  
  844.         if (terrain_type == 1 && !enable_hills && !enable_forest)
  845.           XFillArc (xwindow->display,xwindow->window, xwindow->hue[none],
  846.              ipos-(hex_vert-1), jpos-(hex_vert-1), 2*(hex_vert-1), 2*(hex_vert-1), 0, 23040);
  847.         else
  848.           double_copy (xwindow, square, windowcolor, squaresize, terrain_type, offset);
  849.       }
  850.       else
  851.       {
  852.         offset = ((double)(-terrain_type) * squaresize)/(2*fillnumber);
  853.  
  854.         if (terrain_type < 0)
  855.           terrain_type = 0;
  856.         else
  857.           offset = 0;
  858.  
  859.         if (offset != 0)
  860.           XCopyArea (xwindow->display, xwindow->terrain[1], xwindow->window,
  861.                       xwindow->hue[dark], 0, 0, squaresize, squaresize, ipos, jpos);
  862.   
  863.         XCopyArea (xwindow->display, xwindow->terrain[terrain_type], xwindow->window,
  864.                           xwindow->hue[dark], 0, 0, squaresize-2*offset, squaresize-2*offset,
  865.                           ipos+offset, jpos+offset);
  866.       }
  867.  
  868.       if (enable_basemap[windowcolor] && growth > 50)
  869.       {
  870.         if (enable_hex)
  871.         {
  872.           csize = ((growth - 52)*7*hex_vert)/200;
  873.           hafc = csize/2;
  874.  
  875.           XDrawArc(xwindow->display,xwindow->window,xwindow->hue[dark],
  876.                ipos-hafc, jpos-hafc, csize, csize, 0, square->angle);
  877.  
  878.           XDrawArc(xwindow->display,xwindow->window,xwindow->hue[dark],
  879.                ipos-hafc + 1, jpos-hafc + 1, csize - 2, csize - 2, 0, square->angle);
  880.         }
  881.         else
  882.         {
  883.           csize = ((growth - 52)*squaresize)/50;
  884.           hafc = (squaresize - csize)/2;
  885.           XDrawArc(xwindow->display,xwindow->window,xwindow->hue[dark],
  886.                ipos+hafc, jpos+hafc, csize, csize, 0, 23040);
  887.  
  888.           XDrawArc(xwindow->display,xwindow->window,xwindow->hue[dark],
  889.                    ipos+hafc + 1, jpos+hafc + 1, csize - 2, csize - 2, 0, 23040);
  890.         }
  891.       }
  892.     }
  893.     else
  894.     {
  895.       if (enable_hex)
  896.       {
  897.         /** Using double copy results in some aliasing due to fact that hue[none] is **/
  898.         /** usually drawn not copied and is a stipple.                     **/ 
  899. /**
  900.         double_copy (xwindow, square, windowcolor, squaresize, 1, 0);
  901. **/
  902.  
  903.         blanksquare(xwindow, square, windowcolor, squaresize, TRUE);
  904.       }
  905.       else
  906.         XFillRectangle(xwindow->display,xwindow->window,
  907.                        xwindow->hue[none], ipos,jpos, squaresize, squaresize);
  908.     }
  909.   }
  910.   else
  911.   {
  912.      if (enable_hex) 
  913.      {
  914.         XFillArc (xwindow->display,xwindow->window, xwindow->hue[none],
  915.            ipos-(hex_vert-1), jpos-(hex_vert-1), 2*(hex_vert-1), 2*(hex_vert-1), 0, 23040);
  916. /**
  917.         blanksquare(xwindow, square, windowcolor, squaresize, TRUE);
  918. **/
  919.      }
  920.      else
  921.        XFillRectangle(xwindow->display,xwindow->window,
  922.                      xwindow->hue[none],
  923.                      ipos,jpos, squaresize, squaresize);
  924.  
  925.     if (enable_basemap[windowcolor])
  926.     {
  927.       if (growth > 50 && !enable_localmap[windowcolor] && seen)
  928.       {
  929.         if (enable_hex) 
  930.         {
  931.           csize = ((growth - 52)*7*hex_vert)/200;
  932.           hafc = csize/2;
  933.  
  934.           XDrawArc(xwindow->display,xwindow->window,xwindow->hue[dark],
  935.                ipos-hafc, jpos-hafc, csize, csize, 0, square->angle);
  936.  
  937.           XDrawArc(xwindow->display,xwindow->window,xwindow->hue[dark],
  938.                ipos-hafc + 1, jpos-hafc + 1, csize - 2, csize - 2, 0, square->angle);
  939.         }
  940.         else
  941.         {
  942.           csize = ((growth - 52)*squaresize)/50;
  943.           hafc = (squaresize - csize)/2;
  944.  
  945.           XDrawArc(xwindow->display,xwindow->window,xwindow->hue[dark],
  946.              ipos+hafc, jpos+hafc, csize, csize, 0, 23040);
  947.  
  948.           XDrawArc(xwindow->display,xwindow->window,xwindow->hue[dark],
  949.                ipos+hafc + 1, jpos+hafc + 1, csize - 2, csize - 2, 0, 23040);
  950.         }
  951.       }
  952.     }
  953.   }
  954.  
  955.   if (!enable_hex && enable_grid[windowcolor])
  956.   {
  957.      XDrawLine(xwindow->display,xwindow->window,xwindow->hue[dark],
  958.            ipos,jpos,
  959.            ipos+squaresize,jpos);
  960.      XDrawLine(xwindow->display,xwindow->window,xwindow->hue[dark],
  961.            ipos,jpos,
  962.            ipos,jpos+squaresize);
  963.   }
  964. }
  965.  
  966.  
  967. /*************************************************************************/
  968. /**    storedrawsquare                              **/
  969. /** Draw one square of the game board to a file                **/
  970. /**    Greg Lesher (lesher@park.bu.edu)                **/
  971. /*************************************************************************/
  972. storedrawsquare(square, squaresize, special_flag)
  973.   square_type *square;
  974.   int squaresize,
  975.       special_flag;
  976. {
  977.   int i, j, k,
  978.       bsize, csize, psize, psize1,
  979.       value,
  980.       max, smax, max_pos, smax_pos;
  981.  
  982.   i = square->x;
  983.   j = square->y;
  984.  
  985.   if (enable_hex)
  986.     bsize = 9*hex_vert/5;
  987.   else
  988.     bsize = squaresize;
  989.  
  990.   if (enable_terrain)
  991.   {
  992.     if (enable_hex && special_flag)
  993.     {
  994.       if (!enable_hills && !enable_forest && square->value[none] == 1)
  995.         fprintf (fpout,"b%c%c",i,j);
  996.       else
  997.         fprintf (fpout,"A%c%c%c",i,j,square->value[none]);
  998.     }
  999.     else
  1000.       fprintf (fpout,"A%c%c%c",i,j,square->value[none]);
  1001.   }
  1002.   else
  1003.   {
  1004.     if (enable_hex && special_flag)
  1005.       fprintf (fpout,"b%c%c",i,j);
  1006.     else
  1007.       fprintf (fpout,"B%c%c",i,j);
  1008.   }
  1009.   
  1010.   /**** singularly occupied square ****/
  1011.   if (square->color != none && square->color != FIGHT)
  1012.   {
  1013.     storedrawarrows(square,i,j,square->color);
  1014.  
  1015.     value = square->value[square->color];
  1016.     if (value < 0)
  1017.       value = 0;
  1018.     psize = (int)(bsize * areavalue[value]);
  1019.     
  1020.     fprintf (fpout,"D%c%c%c%c",i,j,psize,square->color);
  1021.   }
  1022.   else if(square->color == FIGHT)
  1023.   {
  1024.     /**** find two largest components of square ****/
  1025.     max = -1;
  1026.     smax = -1; 
  1027.     for (k=0;k<nsides;k++)
  1028.     {
  1029.       if (square->value[k] > max)
  1030.       {
  1031.         smax = max; 
  1032.         smax_pos = max_pos;
  1033.         max = square->value[k];
  1034.         max_pos = k;
  1035.       }
  1036.       else if (square->value[k] > smax)
  1037.       {
  1038.         smax = square->value[k];
  1039.         smax_pos = k;
  1040.       }
  1041.     }
  1042.     psize = (int)(bsize * areavalue[square->value[max_pos]]);
  1043.     psize1 = (int)(bsize * areavalue[square->value[smax_pos]]);
  1044.  
  1045.     fprintf (fpout,"E%c%c%c%c%c%c",i,j,psize,max_pos,psize1,smax_pos);
  1046.   }
  1047.  
  1048.   /**** draw circle for town or base ****/
  1049.   if(square->angle > 0)
  1050.   {
  1051.     if (enable_hex)
  1052.     {
  1053.       if (square->angle < 23040)
  1054.         csize = ((square->oldgrowth - 52)*7*hex_vert)/200;
  1055.       else
  1056.         csize = ((square->growth - 52)*7*hex_vert)/200;
  1057.     }
  1058.     else
  1059.     {
  1060.       if (square->angle < 23040)
  1061.         csize = ((square->oldgrowth - 52)*squaresize)/50;
  1062.       else
  1063.         csize = ((square->growth - 52)*squaresize)/50;
  1064.     }
  1065.  
  1066.     fprintf (fpout,"F%c%c%c%c",i,j,csize,(square->angle*255)/23040);
  1067.   }
  1068. }
  1069.  
  1070.  
  1071. /*************************************************************************/
  1072. /**     storedrawarrows                                                 **/
  1073. /**  Draws appropriate movement arrows to file                **/
  1074. /**     Greg Lesher (lesher@park.bu.edu)                                **/
  1075. /*************************************************************************/
  1076. storedrawarrows(square,i,j,colornumber)
  1077.   square_type *square;
  1078.   int i, j,
  1079.       colornumber;
  1080. {
  1081.   if (enable_hex)
  1082.   {
  1083.     if(square->dir[HEX_UP])
  1084.       fprintf (fpout,"G%c%c%cu",i,j,colornumber);
  1085.  
  1086.     if(square->dir[HEX_DOWN])
  1087.       fprintf (fpout,"G%c%c%cd",i,j,colornumber);
  1088.  
  1089.     if(square->dir[HEX_RIGHT_UP])
  1090.       fprintf (fpout,"G%c%c%cR",i,j,colornumber);
  1091.  
  1092.     if(square->dir[HEX_RIGHT_DOWN])
  1093.       fprintf (fpout,"G%c%c%cr",i,j,colornumber);
  1094.  
  1095.     if(square->dir[HEX_LEFT_UP])
  1096.       fprintf (fpout,"G%c%c%cL",i,j,colornumber);
  1097.  
  1098.     if(square->dir[HEX_LEFT_DOWN])
  1099.       fprintf (fpout,"G%c%c%cl",i,j,colornumber);
  1100.   }
  1101.   else
  1102.   {
  1103.     if(square->dir[UP])
  1104.       fprintf (fpout,"G%c%c%cu",i,j,colornumber);
  1105.  
  1106.     if(square->dir[DOWN])
  1107.       fprintf (fpout,"G%c%c%cd",i,j,colornumber);
  1108.  
  1109.     if(square->dir[RIGHT])
  1110.       fprintf (fpout,"G%c%c%cr",i,j,colornumber);
  1111.  
  1112.     if(square->dir[LEFT])
  1113.       fprintf (fpout,"G%c%c%cl",i,j,colornumber);
  1114.   }
  1115. }
  1116.  
  1117.  
  1118. /*************************************************************************/
  1119. /**    print_message                            **/
  1120. /** Print the latest message to the screen.  The message is purposely    **/
  1121. /** allowed to flash in order to attract attention.  Further attention    **/
  1122. /** can be called by use of ^g to ring the bell.            **/
  1123. /**    Steve Lehar (slehar@park.bu.edu)                **/
  1124. /**    Greg Lesher (lesher@park.bu.edu)                **/
  1125. /*************************************************************************/
  1126. print_message(text,textcount,newcolor,player,board)
  1127.   char text[];
  1128.   int textcount,
  1129.       newcolor,
  1130.       player;
  1131.   square_type *board;
  1132. {
  1133.   int i,
  1134.       scroll, scrollandprint;
  1135.  
  1136.   static oldcolor=0,
  1137.          veryfirst=TRUE,
  1138.          firsttime[MAXSIDES];
  1139.  
  1140.   char oldmessage[512],
  1141.        line[100];
  1142.  
  1143.   if (veryfirst)
  1144.   {
  1145.     for (i=0; i<MAXSIDES; i++)
  1146.       firsttime[i] = TRUE;
  1147.     veryfirst = FALSE;
  1148.   }
  1149.  
  1150.   scroll = FALSE;
  1151.   scrollandprint = FALSE;
  1152.  
  1153. #if !MULTITEXT
  1154.   /**** copy old message ****/
  1155.   strcpy (oldmessage,messagestr);
  1156.   if (newcolor != oldcolor)
  1157.     strcpy(messagestr,"");
  1158. #endif
  1159.  
  1160.   /**** remove control, shift & meta ****/
  1161.   if (textcount==0)
  1162.     return;
  1163.  
  1164.   text[textcount] = 0;
  1165.  
  1166.   if (firsttime[newcolor])
  1167.   {
  1168.     strcpy(personal_messagestr[newcolor], "");
  1169.     firsttime[newcolor] = FALSE;
  1170.   }
  1171.   
  1172.   switch (text[0])
  1173.   {
  1174.     /**** backspace ****/
  1175.     case BACKSPACE:
  1176.     case DELETE:
  1177. #if MULTITEXT
  1178.       if (strlen(personal_messagestr[newcolor]) > 0)
  1179.         personal_messagestr[newcolor][(strlen(personal_messagestr[newcolor]))-1] =
  1180.                                                   messagestr[(strlen(personal_messagestr[newcolor]))];
  1181. #else
  1182.       if (strlen(messagestr) > 0)
  1183.         messagestr[(strlen(messagestr))-1] = messagestr[(strlen(messagestr))];
  1184. #endif
  1185.       break;
  1186.  
  1187.     /**** newline ****/
  1188.     case RETURN:
  1189. #if MULTITEXT
  1190.       strcpy(personal_messagestr[newcolor],"");
  1191. #else
  1192.       scroll = TRUE;
  1193. #endif
  1194.       break;
  1195.     
  1196.     case CTRLC:
  1197.     case CTRLQ:
  1198.       firsttime[newcolor] = TRUE;
  1199.       removeplayer (player, board);
  1200.       break;
  1201.  
  1202.     case CTRLP:
  1203.       gamestats (board);
  1204.       dump_board (board, "xbattle.xbt");
  1205.       break;
  1206.  
  1207.     case CTRLW:
  1208.       winwatch[player] = TRUE;
  1209.       enable_personalhorizon[colorarray[player]] = FALSE;
  1210.       drawboard (board, player, TRUE);
  1211.       firsttime[newcolor] = TRUE;
  1212.       sprintf (line, "%s has quit the game", huename[sidemap[colorarray[player]]]);
  1213.       print_message(line,strlen(line),colorarray[player],player,board);
  1214.       for (i=0; i<nplayers; i++)
  1215.         if (winopen[i]) XBell(xwindow[i]->display,100);
  1216.       break;
  1217.  
  1218.     case CTRLG:
  1219.       for (i=0; i<nplayers; i++)
  1220.         if (winopen[i])
  1221.           XBell(xwindow[i]->display,100);
  1222.       break;
  1223.  
  1224.     case SPACE:
  1225. #if MULTITEXT
  1226.       if ((strlen(personal_messagestr[newcolor]) + 1) > 511)
  1227.       {
  1228.         scroll = TRUE;
  1229.       }
  1230.       else
  1231.         strcat(personal_messagestr[newcolor]," ");
  1232. #else
  1233.       if ((strlen(messagestr) + 1) > 511)
  1234.       {
  1235.         scroll = TRUE;
  1236.       }
  1237.       else
  1238.         strcat(messagestr," ");
  1239. #endif
  1240.  
  1241.       break;
  1242.  
  1243.     default:
  1244. #if MULTITEXT
  1245.       if ((strlen(personal_messagestr[newcolor]) + strlen(text)) > 511)
  1246.       {
  1247.         scroll = TRUE;
  1248.       }
  1249.       else
  1250.         strcat(personal_messagestr[newcolor],text);
  1251. #else
  1252.       if ((strlen(messagestr) + strlen(text)) > 511)
  1253.       {
  1254.         scroll = TRUE;
  1255.       }
  1256.       else
  1257.         strcat(messagestr,text);
  1258. #endif
  1259.  
  1260.       break;
  1261.   }
  1262.  
  1263. #if !MULTITEXT
  1264.   if (newcolor != oldcolor)
  1265.     scrollandprint = TRUE;
  1266. #endif
  1267.  
  1268.   /**** print the string on all xwindows ****/
  1269.   for (i=0; i<nplayers; i++)
  1270.   {
  1271.     if (!winopen[i])
  1272.       continue;
  1273. #if !MULTITEXT
  1274.     /**** scroll bottom text line up ****/
  1275.     if (scroll || scrollandprint)
  1276.     {
  1277.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  1278.                xwindow[i]->hue[oldcolor],
  1279.                TEXTX,textyh[colorarray[i]][newcolor],
  1280.                blankline,strlen(blankline));
  1281.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  1282.                xwindow[i]->hue[oldcolor],
  1283.                TEXTX,textyh[colorarray[i]][newcolor],
  1284.                oldmessage,strlen(oldmessage));
  1285.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  1286.                xwindow[i]->hue[newcolor],
  1287.                TEXTX,textyl[colorarray[i]][newcolor],
  1288.                blankline,strlen(blankline));
  1289.     }
  1290.  
  1291.     /**** print new text line ****/
  1292.     if (scrollandprint || !scroll)
  1293.     {
  1294.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  1295.                xwindow[i]->hue[newcolor],
  1296.                TEXTX,textyl[colorarray[i]][newcolor],
  1297.                blankline,strlen(blankline));
  1298.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  1299.                xwindow[i]->hue[newcolor],
  1300.                TEXTX,textyl[colorarray[i]][newcolor],
  1301.                messagestr,strlen(messagestr));
  1302.     }
  1303. #else
  1304.     /**** print new text line ****/
  1305.     if (scrollandprint || !scroll)
  1306.     {
  1307.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  1308.                xwindow[i]->hue[newcolor],
  1309.                TEXTX,textyh[colorarray[i]][newcolor],
  1310.                blankline,strlen(blankline));
  1311.       XDrawImageString(xwindow[i]->display,xwindow[i]->window,
  1312.                xwindow[i]->hue[newcolor],
  1313.                TEXTX,textyh[colorarray[i]][newcolor],
  1314.                personal_messagestr[newcolor],strlen(personal_messagestr[newcolor]));
  1315.     }
  1316. #endif
  1317.   }
  1318.  
  1319. #if !MULTITEXT
  1320.   if (scrollandprint || !scroll)
  1321.     oldcolor=newcolor;
  1322. #endif
  1323.  
  1324.   if (scroll)
  1325.     strcpy(messagestr,"");
  1326. }
  1327.