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

  1. #include "ext.h"
  2.  
  3. move_def()
  4. {
  5.    int i;
  6.  
  7.    for (i = 0; i < n_units; ++i)
  8.       if (unit[i].status == OK)
  9.       {
  10.          if (unit[i].moves_left > 0) describe_action("Move",i);
  11.          while (unit[i].moves_left > 0 && unit[i].status == OK)
  12.             getmove(i);
  13.       }
  14. }
  15.  
  16. getmove(i)
  17. int i;
  18. {
  19.    char nomove, bad_char, a, b, dir, olda, oldb;
  20.  
  21.    nomove = TRUE;
  22.    while (nomove)
  23.    {
  24.       a = unit[i].l_hex;
  25.       b = unit[i].r_hex;
  26.       movecur_hex(a, b);
  27.       bad_char = FALSE;
  28.  
  29.       dir = Amiga_getchar();
  30.       switch (dir)
  31.       {
  32.          case RIGHT:
  33.             --a;
  34.             --b;
  35.             break;
  36.          case UPRIGHT:
  37.             --a;
  38.             break;
  39.          case DOWNRIGHT:
  40.             --b;
  41.             break;
  42.          case LEFT:
  43.             ++a;
  44.             ++b;
  45.             break;
  46.          case UPLEFT:
  47.             ++b;
  48.             break;
  49.          case DOWNLEFT:
  50.             ++a;
  51.             break;
  52.          case SIT:
  53.          case ' ':
  54.             unit[i].moves_left = 0;
  55.             return(0);
  56.          default:
  57.             bad_char = TRUE;
  58.             break;
  59.       }
  60.  
  61.       if (off_map(a, b) || (occupied(a, b) && unit[i].moves_left == 1) ||
  62.          blocked(a, b) || bad_char)
  63.       {
  64.          bad_char = FALSE;
  65.       }
  66.       else
  67.       {
  68.          olda = unit[i].l_hex;
  69.          oldb = unit[i].r_hex;
  70.          unit[i].l_hex = a;
  71.          unit[i].r_hex = b;
  72.          update_hex(olda, oldb);
  73.          nomove = FALSE;
  74.          unit[i].moves_left -= 1;
  75.          def_ram(i);
  76.          update_hex(unit[i].l_hex, unit[i].r_hex);
  77.       }
  78.    }
  79. }
  80.