home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 030.lha / Ogre / map.c < prev    next >
C/C++ Source or Header  |  1986-11-10  |  5KB  |  292 lines

  1. #include "ext.h"
  2. #include <ctype.h>
  3.  
  4. init_screen()
  5. {
  6.    int a, b;
  7.    char row, col;
  8.  
  9.    tc_setup();
  10.  
  11.    for (a = 1; a <= 28; ++a)
  12.    {
  13.       for (b = 1; b <= 28; ++b)
  14.          if (!off_map(a,b))
  15.             disp_hex(a, b, '7');
  16.    }
  17.  
  18.    disp_craters();
  19.  
  20.    /* refresh the screen */
  21.  
  22.    refresh();
  23. }
  24.  
  25. to_xy(lhex, rhex, row, col)
  26. char lhex, rhex, *row, *col;
  27. {
  28.    *row = (lhex - rhex) + 7;
  29.    *col = 50 - (lhex + rhex);
  30. }
  31.  
  32. off_map(a, b)
  33. char a, b;
  34. {
  35.    char row, col;
  36.  
  37.    to_xy(a, b, &row, &col);
  38.    if (col < 0 || col > 38 || row < 0 || row > 14) return(TRUE);
  39.    else return(FALSE);
  40. }
  41.  
  42. off_obstructed(a, b)
  43. char a, b;
  44. {
  45.    char row, col;
  46.  
  47.    to_xy(a, b, &row, &col);
  48.    if (col < 10 || col > 38 || row < 0 || row > 14) return(TRUE);
  49.    else return(FALSE);
  50. }
  51.  
  52. disp_hex(a, b, c)
  53. char a, b, c;
  54. {
  55.    char row, col;
  56.  
  57.    to_xy(a, b, &row, &col);
  58.    movecur(row, col * 2 + 1);
  59.    Amiga_putchar(c);
  60. }
  61.  
  62. update_hex(a, b)
  63. char a, b;
  64. {
  65.    int i;
  66.  
  67.    if (ogre.l_hex == a && ogre.r_hex == b)
  68.    {
  69.       disp_ogre();
  70.       return;
  71.    }
  72.  
  73.    for (i = 0; i < n_units; ++i)
  74.       if (unit[i].l_hex == a && unit[i].r_hex == b && unit[i].status !=
  75.          DESTROYED)
  76.       {
  77.          disp_unit(i);
  78.          return;
  79.       }
  80.  
  81.    if (blocked(a, b))
  82.    {
  83.       disp_hex(a, b, '*');
  84.       return;
  85.    }
  86.    disp_hex(a, b, '7');
  87. }
  88.  
  89. disp_unit(i)
  90. int i;
  91. {
  92.    char a, b;
  93.  
  94.    a = unit[i].l_hex;
  95.    b = unit[i].r_hex;
  96.    switch(unit[i].status)
  97.    {
  98.       case OK:
  99.          switch (unit[i].type)
  100.          {
  101.             case INFANTRY:
  102.                disp_hex(a, b, '0' + unit[i].attack);
  103.                break;
  104.             default:
  105.                disp_hex(a, b, unit[i].type);
  106.                break;
  107.          }
  108.          break;
  109.  
  110.       case DISABLED:
  111.          disp_hex(a, b, tolower(unit[i].type));
  112.          break;
  113.  
  114.       case DESTROYED:
  115.          disp_hex(a, b, '7');
  116.          break;
  117.    }
  118. }
  119.  
  120. disp_ogre(i)
  121. int i;
  122. {
  123.    /* these are Amiga console control strings for changing colour */
  124.  
  125.    static char  black_on[] =
  126.    {
  127.        0x9b, '1', ';', '3', '2', ';', '4', '0', 'm', '\0'
  128.    };
  129.    static char black_off[] =
  130.    {
  131.        0x9b, '0', ';', '3', '1', ';', '4', '0', 'm', '\0'
  132.    };
  133.    char a, b;
  134.  
  135.    a = ogre.l_hex;
  136.    b = ogre.r_hex;
  137.  
  138.    Amiga_puts(black_on);
  139.    disp_hex(a, b, 'O');
  140.    Amiga_puts(black_off);
  141. }
  142.  
  143. movecur_hex(a, b)
  144. char a, b;
  145. {
  146.    char row, col;
  147.  
  148.    to_xy(a, b, &row, &col);
  149.    movecur(row, col * 2 + 1);
  150. }
  151.  
  152. movecur_unit(i)
  153. int i;
  154. {
  155.    movecur_hex(unit[i].l_hex, unit[i].r_hex);
  156. }
  157.  
  158. #define ABS(i) (((i) < 0) ? -(i) : (i))
  159. #define BIGINT 32767
  160.  
  161. range(a1, b1, a2, b2)
  162. char a1, a2, b1, b2;
  163. {
  164.    char diff1, diff2, temp;
  165.    int subrange[3], min, i, rangesum;
  166.  
  167.    diff1 = a1 - b1;
  168.    diff2 = a2 - b2;
  169.  
  170.    subrange[0] = ABS(a1 - a2);
  171.    subrange[1] = ABS(b1 - b2);
  172.    subrange[2] = ABS(diff1 - diff2);
  173.  
  174.    min = 0;
  175.    for (i = 1; i < 3; ++i)
  176.       if (subrange[i] < subrange[min]) min = i;
  177.  
  178.    rangesum = subrange[min];
  179.    temp = subrange[min];
  180.    subrange[min] = subrange[2];
  181.    subrange[2] = temp;
  182.    min = 0;
  183.    for (i = 1; i < 2; ++i)
  184.       if (subrange[i] < subrange[min]) min = i;
  185.  
  186.    rangesum += subrange[min];
  187.    return(rangesum);
  188. }
  189.  
  190. static struct
  191. {
  192.    char l_hex, r_hex;
  193. }
  194. craters[] =
  195. {
  196.    17, 16,
  197.    19, 13,
  198.    13, 18,
  199.    14, 15,
  200.    13, 15,
  201.    15, 10,
  202.    9,  15,
  203.    10, 12,
  204.    7,  14,
  205.    11, 10,
  206.    14, 7,
  207.    12, 6,
  208.    7, 10,
  209.    8, 6,
  210.    4, 9,
  211.    9, 4,
  212.    9, 3,
  213. };
  214.  
  215. #define NCRATERS (sizeof(craters) / 2 * sizeof(char))
  216.  
  217. blocked(a, b)
  218. char a, b;
  219. {
  220.    int i;
  221.  
  222.    for (i = 0; i < NCRATERS; ++i)
  223.       if (craters[i].l_hex == a && craters[i].r_hex == b) return(TRUE);
  224.    return(FALSE);
  225. }
  226.  
  227. disp_craters()
  228. {
  229.    int i;
  230.  
  231.    for (i = 0; i < NCRATERS; ++i)
  232.       disp_hex(craters[i].l_hex, craters[i].r_hex, '*');
  233. }
  234.  
  235. describe_action(action, i)
  236. char *action;
  237. int i;
  238. {
  239.    char c[80];
  240.  
  241.    switch(unit[i].type)
  242.    {
  243.       case HOWITZER:
  244.          movecur(16, 1);
  245.          eeol(16);
  246.          sprintf(c, "%s howitzer (%d/%d D%d M%d)", action,
  247.             unit[i].attack, unit[i].range, unit[i].defend,
  248.             unit[i].moves_left);
  249.          Amiga_puts(c);
  250.          break;
  251.  
  252.       case MSLTANK:
  253.          movecur(16, 1);
  254.          eeol(16);
  255.          sprintf(c, "%s missile tank (%d/%d D%d M%d)", action,
  256.             unit[i].attack, unit[i].range, unit[i].defend,
  257.             unit[i].moves_left);
  258.          Amiga_puts(c);
  259.          break;
  260.  
  261.       case GEV:
  262.          movecur(16, 1);
  263.          eeol(16);
  264.          sprintf(c, "%s GEV (%d/%d D%d M%d)", action,
  265.             unit[i].attack, unit[i].range, unit[i].defend,
  266.             unit[i].moves_left);
  267.          Amiga_puts(c);
  268.          break;
  269.  
  270.       case HVYTANK:
  271.          movecur(16, 1);
  272.          eeol(16);
  273.          sprintf(c, "%s heavy tank (%d/%d D%d M%d)", action,
  274.             unit[i].attack, unit[i].range, unit[i].defend,
  275.             unit[i].moves_left);
  276.          Amiga_puts(c);
  277.          break;
  278.  
  279.       case INFANTRY:
  280.          movecur(16, 1);
  281.          eeol(16);
  282.          sprintf(c, "%s infantry (%d/%d D%d M%d)", action,
  283.             unit[i].attack, unit[i].range, unit[i].defend,
  284.             unit[i].moves_left);
  285.          Amiga_puts(c);
  286.          break;
  287.  
  288.    }
  289. }
  290.  
  291. /* routines display() and display_xy() have been removed */
  292.