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

  1. #include "ext.h"
  2.  
  3. static OGRE allocated;
  4.  
  5. #define PASS      'p'
  6. #define NOPASS    '\0'
  7. #define RESOLVE   'r'
  8. #define MISSILE   'm'
  9. #define MAIN      'b'
  10. #define SECONDARY 's'
  11. #define AP        'a'
  12. #define TREAD     't'
  13.  
  14. attack_def()
  15. {
  16.         char moreunits;
  17.         int i;
  18.  
  19.         moreunits = TRUE;
  20.         zero(&allocated, sizeof(allocated));
  21.         init_def_attack();
  22.  
  23.         while (moreunits)
  24.         {
  25.                 moreunits = FALSE;
  26.                 for (i = 0; i < n_units; i++)
  27.                 {
  28.                         /*
  29.                          * Don't bother attacking if Ogre is immobile - H.O.
  30.                          */
  31.                         if (ogre.movement == 0)
  32.                            check_over();
  33.  
  34.                         if (unit[i].status == OK && !unit[i].fired &&
  35.                                 unit[i].attack > 0 &&
  36.                                 unit[i].range_to_ogre <= unit[i].range)
  37.                         {
  38.                                 describe_action("Fire",i);
  39.                                 if (get_target(i) == PASS) moreunits = TRUE;
  40.                                 else unit[i].fired = TRUE;
  41.                         }
  42.                 }
  43.         }
  44.         ogre_resolve(&allocated);
  45. }
  46.  
  47. get_target(i)
  48. int i;
  49. {
  50.         char action, invalid;
  51.  
  52.         movecur_unit(i);
  53.  
  54.         do
  55.         {
  56.                 invalid = FALSE;
  57.                 action = Amiga_getchar();
  58.  
  59.                 switch (action)
  60.                 {
  61.                         case PASS:
  62.                                 return(PASS);
  63.  
  64.                         case MISSILE:
  65.                                 if (ogre.missiles > 0)
  66.                                 {
  67.                                        allocated.missiles += unit[i].attack;
  68.                                         update_odds(action);
  69.                                 }
  70.                                 else
  71.                                         invalid = TRUE;
  72.                                 break;
  73.  
  74.                         case MAIN:
  75.                                 if (ogre.main_bats > 0)
  76.                                 {
  77.                                        allocated.main_bats +=unit[i].attack;
  78.                                         update_odds(action);
  79.                                 }
  80.                                 else
  81.                                         invalid = TRUE;
  82.                                 break;
  83.  
  84.                         case SECONDARY:
  85.                                 if (ogre.sec_bats > 0)
  86.                                 {
  87.                                        allocated.sec_bats +=unit[i].attack;
  88.                                         update_odds(action);
  89.                                 }
  90.                                 else
  91.                                         invalid = TRUE;
  92.                                 break;
  93.  
  94.                         case AP:
  95.                                 if (ogre.ap > 0)
  96.                                 {
  97.                                         allocated.ap += unit[i].attack;
  98.                                         update_odds(action);
  99.                                 }
  100.                                 else
  101.                                         invalid = TRUE;
  102.                                 break;
  103.  
  104.                         case TREAD:
  105.                                 if (ogre.treads > 0)
  106.                                 {
  107.                                         allocated.treads += unit[i].attack;
  108.                                         update_odds(action);
  109.                                 }
  110.                                 else
  111.                                         invalid = TRUE;
  112.                                 if (invalid) break;
  113.                                 ogre_resolve(&allocated);
  114.                                 zero(&allocated,sizeof(allocated));
  115.                                 break;
  116.  
  117.                         case RESOLVE:
  118.                                 ogre_resolve(&allocated);
  119.                                 zero(&allocated, sizeof(allocated));
  120.                                 return(PASS);
  121.                                 break;
  122.  
  123.                         default:
  124.                                 invalid = TRUE;
  125.                                 break;
  126.                 }
  127.         } while (invalid);
  128.  
  129.         return(NOPASS);
  130. }
  131.  
  132. zero(area, size)
  133. char *area;
  134. int size;
  135. {
  136.         int i;
  137.  
  138.         for (i = 0; i < size; i++) area[i] = '\0';
  139. }
  140.  
  141. update_odds(weapon)
  142. char weapon;
  143. {
  144.         char c[80];
  145.         static char blanks[10] = {"          "};
  146.         char *odd_str();
  147.  
  148.         switch (weapon)
  149.         {
  150.                 case MAIN:
  151.                        movecur(18, 40);
  152.                        Amiga_puts(blanks);
  153.                        movecur(18, 40);
  154.                        sprintf(c,"%d %d (%s)",allocated.main_bats,
  155.                           DEF_MAIN, odd_str(allocated.main_bats, DEF_MAIN));
  156.                        Amiga_puts(c);
  157.                        break;
  158.  
  159.                 case SECONDARY:
  160.                        movecur(19, 40);
  161.                        Amiga_puts(blanks);
  162.                        movecur(19,40);
  163.                        sprintf(c,"%d %d (%s)",allocated.sec_bats,
  164.                           DEF_SECONDARY, odd_str(allocated.sec_bats,
  165.                           DEF_SECONDARY));
  166.                        Amiga_puts(c);
  167.                        break;
  168.  
  169.                 case MISSILE:
  170.                         movecur(20, 40);
  171.                         Amiga_puts(blanks);
  172.                         movecur(20,40);
  173.                         sprintf(c,"%s", odd_str(allocated.missiles,
  174.                            DEF_MISSILES));
  175.                         Amiga_puts(c);
  176.                         break;
  177.  
  178.                 case AP:
  179.                        movecur(21, 40);
  180.                        Amiga_puts(blanks);
  181.                        movecur(21,40);
  182.                        sprintf(c,"%s",odd_str(allocated.ap,DEF_AP));
  183.                        Amiga_puts(c);
  184.                        break;
  185.  
  186.                 case TREAD:
  187.                         movecur(22, 40);
  188.                         Amiga_puts(blanks);
  189.                         movecur(22,40);
  190.                         sprintf(c,"1/1 (%d)     ", allocated.treads);
  191.                         Amiga_puts(c);
  192.                         break;
  193.         }
  194. }
  195.