home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / AI.c next >
C/C++ Source or Header  |  2009-09-21  |  1KB  |  78 lines

  1. #include <exec/types.h>
  2. #include "h/rot.h"
  3.  
  4. /*
  5. #define MWDEBUG 1
  6. #include "sc:extras/memlib/memwatch.h"
  7. */
  8.  
  9. extern struct gameinfo gi;
  10.  
  11. LONG __asm determineaim(register __d0 LONG dx,
  12.                           register __d1 LONG dy,
  13.                           register __a0 LONG dxdy,
  14.                           register __a1 LONG dydx);
  15.  
  16. LONG detcomplexheading(n,tarx,tary,x,y,pos)
  17. LONG n,tarx,tary,x,y,pos;
  18. {
  19. SHORT dx,dy,dxdy,dydx,aim,s;
  20.  
  21.  
  22. if (tarx-x != 0)
  23.     {
  24.     s = sign(tarx-x);
  25.  
  26.     if (abs(tarx - x) < abs(s*gi.dx-tarx+x)) dx = tarx - x;
  27.     else                                 dx = -s*abs(s*gi.dx-tarx+x);
  28.     }
  29.  
  30. if (tary-y != 0)
  31.     {
  32.     s = sign(tary-y);
  33.  
  34.     if (abs(tary - y) < abs(s*gi.dy-tary+y)) dy = tary - y;
  35.     else                                 dy = -s*abs(s*gi.dy-tary+y);
  36.     }
  37.  
  38. if (dx==0) dx=1;
  39. if (dy==0) dy=1;
  40.  
  41. dxdy = abs((dx*10)/dy);
  42. dydx = abs((dy*10)/dx);
  43.  
  44. aim = determineaim(dx,dy,dxdy,dydx);        /* assembly routine */
  45.  
  46. if (aim == pos) return(0);
  47. else
  48. if ( abs(aim-pos) < abs(aim+31-pos) )   
  49.     return(aim-pos);
  50. else
  51.     return(aim+31-pos);
  52. }
  53.  
  54.  
  55. LONG determineheading(tarx,tary,x,y,pos)
  56. LONG tarx,tary,x,y,pos;
  57. {
  58. SHORT dx,dy,dxdy,dydx,aim;
  59.  
  60. dx = tarx - x;
  61. dy = tary - y;
  62.  
  63. if (dx == 0) dx = 1;
  64. if (dy == 0) dy = 1;
  65.  
  66. dxdy = abs((dx*10)/dy);
  67. dydx = abs((dy*10)/dx);
  68.  
  69. aim = determineaim(dx,dy,dxdy,dydx);        /* assembly routine */
  70.  
  71. if (aim == pos) return(0);
  72. else
  73. if ( abs(aim-pos) < abs(aim+31-pos) )   
  74.     return(aim-pos);
  75. else
  76.     return(aim+31-pos);
  77. }
  78.