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

  1. #include "ext.h"
  2.  
  3. static char *odd_names[] =
  4. {
  5.    "0/1", "1/2", "1/1", "2/1", "3/1", "4/1", "+",
  6. };
  7.  
  8. static char crt[6][7] =
  9. {
  10.    OK, OK,        OK,        OK,        DISABLED,  DISABLED,  DESTROYED,
  11.    OK, OK,        OK,        DISABLED,  DISABLED,  DESTROYED, DESTROYED,
  12.    OK, OK,        DISABLED,  DISABLED,  DESTROYED, DESTROYED, DESTROYED,
  13.    OK, OK,        DISABLED,  DESTROYED, DESTROYED, DESTROYED, DESTROYED,
  14.    OK, DISABLED,  DESTROYED, DESTROYED, DESTROYED, DESTROYED, DESTROYED,
  15.    OK, DESTROYED, DESTROYED, DESTROYED, DESTROYED, DESTROYED, DESTROYED,
  16. };
  17.  
  18. odds(attack, defend)
  19. int  attack, defend;
  20. {
  21.    int result;
  22.  
  23.    result = (defend > 0) ? attack / defend + 1 : 6;
  24.  
  25.    if (result > 6) result = 6;
  26.    if (result == 1)
  27.       result = (2 * attack < defend) ? 0 : 1;
  28.    return(result);
  29. }
  30.  
  31. char *odd_str(attack, defend)
  32. int attack, defend;
  33. {
  34.    return(odd_names[odds(attack, defend)]);
  35. }
  36.  
  37. ogre_resolve(allocations)
  38. OGRE *allocations;
  39. {
  40.    static char blanks[12] = {"           "};
  41.  
  42.    eeol(16);
  43.    Amiga_puts("Resolving...");
  44.    cycle();
  45.  
  46.    if (allocations->missiles > 0)
  47.    {
  48.       if (crt[roll()][odds(allocations->missiles, DEF_MISSILES)] ==
  49.          DESTROYED) ogre.missiles -= 1;
  50.    }
  51.  
  52.    if (allocations->main_bats > 0)
  53.    {
  54.       if (crt[roll()][odds(allocations->main_bats, DEF_MAIN)] ==
  55.          DESTROYED) ogre.main_bats -= 1;
  56.    }
  57.  
  58.    if (allocations->sec_bats > 0)
  59.    {
  60.       if (crt[roll()][odds(allocations->sec_bats, DEF_SECONDARY)] ==
  61.          DESTROYED) ogre.sec_bats -= 1;
  62.    }
  63.  
  64.    if (allocations->ap > 0)
  65.    {
  66.       if (crt[roll()][odds(allocations->ap, DEF_AP)] ==
  67.          DESTROYED) ogre.ap -= 1;
  68.    }
  69.  
  70.    if (allocations->treads > 0)
  71.    {
  72.       if (crt[roll()][odds(1,1)] == DESTROYED)
  73.          decrease_treads(allocations->treads);
  74.    }
  75.    movecur(18, 40);
  76.    Amiga_puts(blanks);
  77.    movecur(19, 40);
  78.    Amiga_puts(blanks);
  79.    movecur(19, 40);
  80.    Amiga_puts(blanks);
  81.    movecur(20, 40);
  82.    Amiga_puts(blanks);
  83.    movecur(21, 40);
  84.    Amiga_puts(blanks);
  85.    movecur(22, 40);
  86.    Amiga_puts(blanks);
  87.  
  88.    disp_ogre_status(FALSE);
  89. }
  90.  
  91. def_resolve(i)
  92. int i;
  93. {
  94.    char result;
  95.  
  96.    if (unit[i].status != DESTROYED && unit[i].fired > 0)
  97.    {
  98.       result = crt[roll()][odds(unit[i].fired, unit[i].defend)];
  99.       if (unit[i].type == INFANTRY)
  100.          if (result == DISABLED)
  101.          {
  102.             unit[i].attack -= 1;
  103.             if (unit[i].attack == 0) unit[i].status = DESTROYED;
  104.             update_hex(unit[i].l_hex, unit[i].r_hex);
  105.             return;
  106.          }
  107.          switch (unit[i].status)
  108.          {
  109.             case OK:
  110.                unit[i].status = result;
  111.                break;
  112.             case DISABLED:
  113.                if (result != OK) unit[i].status = DESTROYED;
  114.                break;
  115.          }
  116.          if (unit[i].status != OK)
  117.             update_hex(unit[i].l_hex, unit[i].r_hex);
  118.     }
  119. }
  120.  
  121. roll()
  122. {
  123.    long lrand48(), k = 0;
  124.  
  125.    while (k == 0)
  126.       k = (lrand48()) % 6;
  127.    return(k);
  128. }
  129.  
  130. ogre_ram()
  131. {
  132.    int i;
  133.  
  134.    for (i = 0; i < n_units; ++i)
  135.       if (unit[i].l_hex ==  ogre.l_hex &&
  136.       unit[i].r_hex == ogre.r_hex &&
  137.       unit[i].status != DESTROYED)
  138.  
  139.       switch (unit[i].type)
  140.       {
  141.          case  INFANTRY:
  142.             if (ogre.ap > 0)
  143.             {
  144.                unit[i].attack -= 1;
  145.                if (unit[i].attack == 0)
  146.                   unit[i].status = DESTROYED;
  147.             }
  148.             break;
  149.          default:
  150.             if (unit[i].movement == 0 || unit[i].status == DISABLED)
  151.             {
  152.                unit[i].status = DESTROYED;
  153.                decrease_treads((unit[i].type == HVYTANK) ? 2 : 1);
  154.                disp_ogre_status(FALSE);
  155.             }
  156.             else
  157.             {
  158.                unit[i].status = (roll() > 3) ? DESTROYED : DISABLED;
  159.                decrease_treads((unit[i].type == HVYTANK) ? 2 : 1);
  160.                disp_ogre_status(FALSE);
  161.             }
  162.             break;
  163.       }
  164. }
  165.  
  166. def_ram(i)
  167. int i;
  168. {
  169.    if (unit[i].l_hex == ogre.l_hex && unit[i].r_hex == ogre.r_hex &&
  170.      unit[i].type != INFANTRY)
  171.    {
  172.       if (unit[i].type == HVYTANK)
  173.          decrease_treads(2);
  174.       else
  175.          decrease_treads(1);
  176.       unit[i].status = DESTROYED;
  177.       disp_ogre_status(FALSE);
  178.    }
  179. }
  180.  
  181. decrease_treads(attack)
  182. int attack;
  183. {
  184.    ogre.treads -= attack;
  185.    ogre.movement = 0;
  186.    if (ogre.treads > 0) ogre.movement = 1;
  187.    if (ogre.treads > ogre.init_treads / 3) ogre.movement = 2;
  188.    if (ogre.treads > 2 * ogre.init_treads / 3) ogre.movement = 3;
  189. }
  190.