home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume7 / omega3 / part19 / ommove.c < prev    next >
C/C++ Source or Header  |  1989-07-20  |  5KB  |  252 lines

  1. /* omega copyright (c) 1987,1988,1989 by Laurence Raphael Brothers */
  2. /* ommove.c */
  3. /* monster move functions */
  4.  
  5. #include "oglob.h"
  6.  
  7.  
  8. /* like m_normal_move, but can open doors */
  9. void m_smart_move(m)
  10. struct monster *m;
  11. {
  12.   m_simple_move(m);
  13. }
  14.  
  15. /* not very smart, but not altogether stupid movement */
  16. void m_normal_move(m)
  17. struct monster *m;
  18. {
  19.   m_simple_move(m);
  20. }
  21.  
  22.  
  23. /* used by both m_normal_move and m_smart_move */
  24. void m_simple_move(m)
  25. struct monster *m;
  26. {
  27.   int dx = sign(Player.x - m->x);
  28.   int dy = sign(Player.y - m->y);
  29.   erase_monster(m);
  30.   if (m->hp < Monsters[m->id].hp/4) {
  31.     dx = - dx;
  32.     dy = - dy;
  33.     m->movef = M_MOVE_SCAREDY;
  34.     if (m->uniqueness == COMMON) {
  35.       strcpy(Str2,"The ");
  36.       strcat(Str2,m->monstring);
  37.     }
  38.     else strcpy(Str2,m->monstring);
  39.     if (m->possessions != NULL) {
  40.       strcat(Str2," drops its treasure and flees!");
  41.       m_dropstuff(m);
  42.     }
  43.     else strcat(Str2," flees!");
  44.     mprint(Str2);
  45.     m->speed = min(2,m->speed-1);
  46.   }
  47.   if ((! m_statusp(m,HOSTILE)) || 
  48.       (Player.status[INVISIBLE] > 0)) m_random_move(m);
  49.   else {
  50.     if (m_unblocked(m,m->x+dx,m->y+dy))
  51.       movemonster(m,m->x+dx,m->y+dy);
  52.     else if (dx == 0) {
  53.       if (m_unblocked(m,m->x+1,m->y+dy))
  54.     movemonster(m,m->x+1,m->y+dy);
  55.       else if (m_unblocked(m,m->x-1,m->y+dy))
  56.     movemonster(m,m->x-1,m->y+dy);
  57.     }
  58.     
  59.     else if (dy == 0) {
  60.       if (m_unblocked(m,m->x+dx,m->y+1))
  61.     movemonster(m,m->x+dx,m->y+1);
  62.       else if (m_unblocked(m,m->x+dx,m->y-1))
  63.     movemonster(m,m->x+dx,m->y-1);
  64.     }
  65.     
  66.     else {
  67.       if (m_unblocked(m,m->x+dx,m->y))
  68.     movemonster(m,m->x+dx,m->y);
  69.       else if (m_unblocked(m,m->x,m->y+dy))
  70.     movemonster(m,m->x,m->y+dy);
  71.     }
  72.   }
  73. }
  74.  
  75.  
  76.  
  77.  
  78. void m_move_animal(m)
  79. struct monster *m;
  80. {
  81.   if (m_statusp(m,HOSTILE))
  82.     m_normal_move(m);
  83.   else m_scaredy_move(m);
  84. }
  85.  
  86.  
  87.  
  88.  
  89. /* same as simple move except run in opposite direction */
  90. void m_scaredy_move(m)
  91. struct monster *m;
  92. {
  93.   int dx = -sign(Player.x - m->x);
  94.   int dy = -sign(Player.y - m->y);
  95.   erase_monster(m);
  96.   if (Player.status[INVISIBLE]) m_random_move(m);
  97.   else {
  98.     if (m_unblocked(m,m->x+dx,m->y+dy))
  99.       movemonster(m,m->x+dx,m->y+dy);
  100.     else if (dx == 0) {
  101.       if (m_unblocked(m,m->x+1,m->y+dy))
  102.     movemonster(m,m->x+1,m->y+dy);
  103.       else if (m_unblocked(m,m->x-1,m->y+dy))
  104.     movemonster(m,m->x-1,m->y+dy);
  105.     }
  106.     
  107.     else if (dy == 0) {
  108.       if (m_unblocked(m,m->x+dx,m->y+1))
  109.     movemonster(m,m->x+dx,m->y+1);
  110.       else if (m_unblocked(m,m->x+dx,m->y-1))
  111.     movemonster(m,m->x+dx,m->y-1);
  112.     }
  113.     
  114.     else {
  115.       if (m_unblocked(m,m->x+dx,m->y))
  116.     movemonster(m,m->x+dx,m->y);
  117.       else if (m_unblocked(m,m->x,m->y+dy))
  118.     movemonster(m,m->x,m->y+dy);
  119.     }
  120.   }
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128. /* for spirits (and earth creatures) who can ignore blockages because
  129.    either they are noncorporeal or they can move through stone */
  130. void m_spirit_move(m)
  131. struct monster *m;
  132. {
  133.   int dx = sign(Player.x - m->x);
  134.   int dy = sign(Player.y - m->y);
  135.   erase_monster(m);
  136.   if (m->hp < Monsters[m->id].hp/6) {
  137.     dx = -dx;
  138.     dy = -dy;
  139.   }
  140.  
  141.   if (Player.status[INVISIBLE] > 0) m_random_move(m);
  142.   else movemonster(m,m->x+dx,m->y+dy);
  143. }
  144.  
  145.  
  146.   
  147. /* fluttery dumb movement */
  148. void m_flutter_move(m)
  149. struct monster *m;
  150. {
  151.   int trange,range = distance(m->x,m->y,Player.x,Player.y);
  152.   int i,tx,ty,nx=m->x,ny=m->y;
  153.   erase_monster(m);
  154.   if (Player.status[INVISIBLE] > 0) m_random_move(m);
  155.   else {
  156.     for (i=0;i<8;i++) {
  157.       tx = m->x+Dirs[0][i];
  158.       ty = m->y+Dirs[1][i];
  159.       trange = distance(tx,ty,Player.x,Player.y);
  160.       if (m->hp < Monsters[m->id].hp/6) {
  161.     if ((trange > range) && m_unblocked(m,tx,ty)) {
  162.       range = trange;
  163.       nx = tx;
  164.       ny = ty;
  165.     }
  166.       }
  167.       else if ((trange <= range) && m_unblocked(m,tx,ty)) {
  168.     range = trange;
  169.     nx = tx;
  170.     ny = ty;
  171.       }
  172.     }
  173.     movemonster(m,nx,ny);
  174.   }
  175. }
  176.  
  177.  
  178. void m_follow_move(m)
  179. struct monster *m;
  180. {
  181.   if (! m_statusp(m,HOSTILE))
  182.     m_normal_move(m);
  183.   else m_scaredy_move(m);
  184. }
  185.  
  186.  
  187.  
  188. /* allows monsters to fall into pools, revealed traps, etc */
  189. void m_confused_move(m)
  190. struct monster *m;
  191. {
  192.   int i,nx,ny,done=FALSE;
  193.   erase_monster(m);
  194.   for (i=0;((i<8)&&(! done));i++) {
  195.     nx = m->x+random_range(3)-1;
  196.     ny = m->y+random_range(3)-1;
  197.     if (unblocked(nx,ny) && 
  198.     ((nx != Player.x) || 
  199.      (ny != Player.y))) {
  200.       done = TRUE;
  201.       movemonster(m,nx,ny);
  202.     }
  203.   }
  204. }
  205.  
  206. void m_random_move(m)
  207. struct monster *m;
  208. {
  209.   int i,nx,ny,done=FALSE;
  210.   erase_monster(m);
  211.   for (i=0;((i<8)&&(! done));i++) {
  212.     nx = m->x+random_range(3)-1;
  213.     ny = m->y+random_range(3)-1;
  214.     if (m_unblocked(m,nx,ny) && 
  215.     ((nx != Player.x) || 
  216.      (ny != Player.y))) {
  217.       done = TRUE;
  218.       movemonster(m,nx,ny);
  219.     }
  220.   }
  221. }
  222.  
  223.     
  224. /* monster removed from play */
  225. void m_vanish(m)
  226. struct monster *m;
  227. {
  228.   if (m->uniqueness == COMMON) {
  229.     strcpy(Str2,"The ");
  230.     strcat(Str2,m->monstring);
  231.   }
  232.   else strcpy(Str2,m->monstring);
  233.   strcat(Str2," vanishes in the twinkling of an eye!");
  234.   mprint(Str2);
  235.   Level->site[m->x][m->y].creature = NULL;
  236.   erase_monster(m);
  237.   m->hp = -1; /* signals "death" -- no credit to payer, though */
  238. }
  239.  
  240. /* monster still in play */
  241. void m_teleport(m)
  242. struct monster *m;
  243. {
  244.   erase_monster(m);
  245.   if (m_statusp(m,AWAKE)) {
  246.     Level->site[m->x][m->y].creature = NULL;
  247.     putspot(m->x,m->y,getspot(m->x,m->y,FALSE));
  248.     findspace(&(m->x),&(m->y),-1);
  249.     Level->site[m->x][m->y].creature = m;
  250.   }
  251. }
  252.