home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1997 January / CD_shareware_1-97.iso / DOS / JUEGOS / QPLUS15.ZIP / AI.QC next >
Encoding:
Text File  |  1996-09-28  |  17.2 KB  |  842 lines

  1. void() movetarget_f;
  2. void() t_movetarget;
  3. void() knight_walk1;
  4. void() knight_bow6;
  5. void() knight_bow1;
  6. void(entity etemp, entity stemp, entity stemp, float dmg) T_Damage;
  7. void() CheckFall;        //ws
  8. void() water_checks;    //ws
  9.  
  10. /*
  11. .enemy
  12. Will be world if not currently angry at anyone.
  13.  
  14. .movetarget
  15. The next path spot to walk toward.  If .enemy, ignore .movetarget.
  16. When an enemy is killed, the monster will try to return to it's path.
  17.  
  18. .hunt_time
  19. Set to time + something when the player is in sight, but movement straight for
  20. him is blocked.  This causes the monster to use wall following code for
  21. movement direction instead of sighting on the player.
  22.  
  23. .ideal_yaw
  24. A yaw angle of the intended direction, which will be turned towards at up
  25. to 45 deg / state.  If the enemy is in view and hunt_time is not active,
  26. this will be the exact line towards the enemy.
  27.  
  28. .pausetime
  29. A monster will leave it's stand state and head towards it's .movetarget when
  30. time > .pausetime.
  31.  
  32. walkmove(angle, speed) primitive is all or nothing
  33. */
  34.  
  35. //
  36. // globals
  37. //
  38. float    current_yaw;
  39.  
  40. //
  41. // when a monster becomes angry at a player, that monster will be used
  42. // as the sight target the next frame so that monsters near that one
  43. // will wake up even if they wouldn't have noticed the player
  44. //
  45. entity    sight_entity;
  46. float    sight_entity_time;
  47.  
  48. float(float v) anglemod =
  49. {
  50.     while (v >= 360)
  51.         v = v - 360;
  52.     while (v < 0)
  53.         v = v + 360;
  54.     return v;
  55. };
  56.  
  57. /*
  58. ==============================================================================
  59.  
  60. MOVETARGET CODE
  61.  
  62. The angle of the movetarget effects standing and bowing direction, but has no effect on movement, which allways heads to the next target.
  63.  
  64. targetname
  65. must be present.  The name of this movetarget.
  66.  
  67. target
  68. the next spot to move to.  If not present, stop here for good.
  69.  
  70. pausetime
  71. The number of seconds to spend standing or bowing for path_stand or path_bow
  72.  
  73. ==============================================================================
  74. */
  75.  
  76. void() movetarget_f =
  77. {
  78.     if (!self.targetname)
  79.         objerror ("monster_movetarget: no targetname");
  80.         
  81.     self.solid = SOLID_TRIGGER;
  82.     self.touch = t_movetarget;
  83.     setsize (self, '-8 -8 -8', '8 8 8');
  84.     
  85. };
  86.  
  87. /*QUAKED path_corner (0.5 0.3 0) (-8 -8 -8) (8 8 8)
  88. Monsters will continue walking towards the next target corner.
  89. */
  90. void() path_corner =
  91. {
  92.     movetarget_f ();
  93. };
  94.  
  95. /*
  96. =============
  97. t_movetarget
  98.  
  99. Something has bumped into a movetarget.  If it is a monster
  100. moving towards it, change the next destination and continue.
  101. ==============
  102. */
  103. void() t_movetarget =
  104. {
  105. local entity    temp;
  106.  
  107.     if (other.movetarget != self)
  108.         return;
  109.     
  110.     if (other.enemy)
  111.         return;        // fighting, not following a path
  112.  
  113.     temp = self;
  114.     self = other;
  115.     other = temp;
  116.  
  117.     if (self.classname == "monster_ogre")
  118.         sound (self, CHAN_VOICE, "ogre/ogdrag.wav", 1, ATTN_IDLE);// play chainsaw drag sound
  119.  
  120. //dprint ("t_movetarget\n");
  121.     self.goalentity = self.movetarget = find (world, targetname, other.target);
  122.     self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin);
  123.     if (!self.movetarget)
  124.     {
  125.         self.pausetime = time + 999999;
  126.         self.th_stand ();
  127.         return;
  128.     }
  129. };
  130.  
  131. //============================================================================
  132.  
  133. /*
  134. =============
  135. range
  136.  
  137. returns the range catagorization of an entity reletive to self
  138. 0    melee range, will become hostile even if back is turned
  139. 1    visibility and infront, or visibility and show hostile
  140. 2    infront and show hostile
  141. 3    only triggered by damage
  142. =============
  143. */
  144.  
  145. float() monster_drown_check =
  146. {
  147. if (self.waterlevel == 1)
  148.     { 
  149.     if (self.air_finished < time)
  150.         {    // drown!
  151.         if (self.pain_finished < time)
  152.             {
  153.             self.dmg = self.dmg + 2;
  154.             if (self.dmg > 15)
  155.                 self.dmg = 10;
  156.             T_Damage (self, world, world, self.dmg);
  157.             self.pain_finished = time + 1;
  158.             }
  159.         }
  160.     }
  161. else self.air_finished = time + 12;
  162. };
  163.  
  164. float(entity targ) range =
  165. {
  166.     if ((self.jump_flag < -300) && (self.flags & FL_ONGROUND) && (self.health > 0))    //ws... fall
  167.     {
  168.                 CheckFall();
  169.     self.jump_flag = 0;
  170.     }            
  171.     if (!(self.flags & FL_ONGROUND))
  172.         self.jump_flag = self.velocity_z;                        //...ws
  173.  
  174.     water_checks();                //ws... drown
  175.     monster_drown_check();    //ws 
  176.     if (self.air_finished - 4 <= time)
  177.     {
  178.         self.velocity_z = self.velocity_z + 100;        // ws what an ugly hack
  179.         if(self.flags & FL_ONGROUND)            //ws
  180.             self.flags = self.flags - FL_ONGROUND;    //ws
  181.     }                    //...ws
  182.  
  183. local vector    spot1, spot2;
  184. local float        r;    
  185.     spot1 = self.origin + self.view_ofs;
  186.     spot2 = targ.origin + targ.view_ofs;
  187.     
  188.     r = vlen (spot1 - spot2);
  189.     if (r < 120)
  190.         return RANGE_MELEE;
  191.     if (r < 500)
  192.         return RANGE_NEAR;
  193.     if (r < 1000)
  194.         return RANGE_MID;
  195.     return RANGE_FAR;
  196. };
  197.  
  198. /*
  199. =============
  200. visible
  201.  
  202. returns 1 if the entity is visible to self, even if not infront ()
  203. =============
  204. */
  205.  
  206. float (entity targ) visible =
  207. {
  208.     local vector    spot1, spot2;
  209.     
  210.     spot1 = self.origin + self.view_ofs;
  211.     spot2 = targ.origin + targ.view_ofs;
  212.     traceline (spot1, spot2, TRUE, self);    // see through other monsters
  213.     
  214.     if (trace_inopen && trace_inwater)
  215.         return FALSE;            // sight line crossed contents
  216.  
  217.     if (trace_fraction == 1)
  218.         return TRUE;
  219.     return FALSE;
  220. };
  221.  
  222. /*
  223. =============
  224. infront
  225.  
  226. returns 1 if the entity is in front (in sight) of self
  227. =============
  228. */
  229.  
  230. float(entity targ) infront =
  231. {
  232.     local vector    vec;
  233.     local float        dot;
  234.     
  235.     makevectors (self.angles);
  236.     vec = normalize (targ.origin - self.origin);
  237.     dot = vec * v_forward;
  238.     
  239.     if ( dot > 0.3)
  240.     {
  241.         return TRUE;
  242.     }
  243.     return FALSE;
  244. };
  245.  
  246.  
  247. //============================================================================
  248.  
  249. /*
  250. ===========
  251. ChangeYaw
  252.  
  253. Turns towards self.ideal_yaw at self.yaw_speed
  254. Sets the global variable current_yaw
  255. Called every 0.1 sec by monsters
  256. ============
  257. */
  258.  
  259. /*
  260. void() ChangeYaw =
  261. {
  262.     local float        ideal, move;
  263.  
  264. //current_yaw = self.ideal_yaw;
  265. // mod down the current angle
  266.     current_yaw = anglemod( self.angles_y );
  267.     ideal = self.ideal_yaw;
  268.     
  269.     if (current_yaw == ideal)
  270.         return;
  271.     
  272.     move = ideal - current_yaw;
  273.     if (ideal > current_yaw)
  274.     {
  275.         if (move > 180)
  276.             move = move - 360;
  277.     }
  278.     else
  279.     {
  280.         if (move < -180)
  281.             move = move + 360;
  282.     }
  283.         
  284.     if (move > 0)
  285.     {
  286.         if (move > self.yaw_speed)
  287.             move = self.yaw_speed;
  288.     }
  289.     else
  290.     {
  291.         if (move < 0-self.yaw_speed )
  292.             move = 0-self.yaw_speed;
  293.     }
  294.  
  295.     current_yaw = anglemod (current_yaw + move);
  296.  
  297.     self.angles_y = current_yaw;
  298. };
  299. */
  300.  
  301. //============================================================================
  302.  
  303. void() HuntTarget =
  304. {
  305.     self.goalentity = self.enemy;
  306.     self.think = self.th_run;
  307.     self.ideal_yaw = vectoyaw(self.enemy.origin - self.origin);
  308.     self.nextthink = time + 0.1;
  309.     SUB_AttackFinished (1);    // wait a while before first attack
  310. };
  311.  
  312. void() SightSound =
  313. {
  314. local float    rsnd;
  315.  
  316.     if (self.classname == "monster_ogre")    
  317.         sound (self, CHAN_VOICE, "ogre/ogwake.wav", 1, ATTN_NORM);
  318.     else if (self.classname == "monster_knight")
  319.         sound (self, CHAN_VOICE, "knight/ksight.wav", 1, ATTN_NORM);
  320.     else if (self.classname == "monster_shambler")
  321.         sound (self, CHAN_VOICE, "shambler/ssight.wav", 1, ATTN_NORM);
  322.     else if (self.classname == "monster_demon1")
  323.         sound (self, CHAN_VOICE, "demon/sight2.wav", 1, ATTN_NORM);
  324.     else if (self.classname == "monster_wizard")
  325.         sound (self, CHAN_VOICE, "wizard/wsight.wav", 1, ATTN_NORM);
  326.     else if (self.classname == "monster_zombie")
  327.         sound (self, CHAN_VOICE, "zombie/z_idle.wav", 1, ATTN_NORM);
  328.     else if (self.classname == "monster_dog")
  329.         sound (self, CHAN_VOICE, "dog/dsight.wav", 1, ATTN_NORM);
  330.     else if (self.classname == "monster_hell_knight")
  331.         sound (self, CHAN_VOICE, "hknight/sight1.wav", 1, ATTN_NORM);
  332.     else if (self.classname == "monster_tarbaby")
  333.         sound (self, CHAN_VOICE, "blob/sight1.wav", 1, ATTN_NORM);
  334.     else if (self.classname == "monster_vomit")
  335.         sound (self, CHAN_VOICE, "vomitus/v_sight1.wav", 1, ATTN_NORM);
  336.     else if (self.classname == "monster_enforcer")
  337.     {
  338.         rsnd = rint(random() * 3);            
  339.         if (rsnd == 1)
  340.             sound (self, CHAN_VOICE, "enforcer/sight1.wav", 1, ATTN_NORM);
  341.         else if (rsnd == 2)
  342.             sound (self, CHAN_VOICE, "enforcer/sight2.wav", 1, ATTN_NORM);
  343.         else if (rsnd == 0)
  344.             sound (self, CHAN_VOICE, "enforcer/sight3.wav", 1, ATTN_NORM);
  345.         else
  346.             sound (self, CHAN_VOICE, "enforcer/sight4.wav", 1, ATTN_NORM);
  347.     }
  348.     else if (self.classname == "monster_army")
  349.         sound (self, CHAN_VOICE, "soldier/sight1.wav", 1, ATTN_NORM);
  350.     else if (self.classname == "monster_shalrath")
  351.         sound (self, CHAN_VOICE, "shalrath/sight.wav", 1, ATTN_NORM);
  352. };
  353.  
  354. void() FoundTarget =
  355. {
  356.     if (self.enemy.classname == "player")
  357.     {    // let other monsters see this monster for a while
  358.         sight_entity = self;
  359.         sight_entity_time = time;
  360.     }
  361.     
  362.     if(self.enemy!=self.friend) 
  363.         self.show_hostile = time + 1;    // wake up other monsters
  364.  
  365.     SightSound ();
  366.     HuntTarget ();
  367. };
  368.  
  369. void() FriendMove = 
  370. {
  371.     local float dir;
  372.  
  373.     if(other != self.friend) return;     // We don't want someone else pushing
  374.     dir = vectoyaw(other.velocity);
  375.     walkmove(dir, 7);
  376. };
  377.  
  378. /*
  379. ===========
  380. FindTarget
  381.  
  382. Self is currently not attacking anything, so try to find a target
  383.  
  384. Returns TRUE if an enemy was sighted
  385.  
  386. When a player fires a missile, the point of impact becomes a fakeplayer so
  387. that monsters that see the impact will respond as if they had seen the
  388. player.
  389.  
  390. To avoid spending too much time, only a single client (or fakeclient) is
  391. checked each frame.  This means multi player games will have slightly
  392. slower noticing monsters.
  393. ============
  394. */
  395.  
  396. void(entity newfriend) player_addfriend;
  397.  
  398. float() FindTarget =
  399. {
  400.     local entity    client, oldself;
  401.     local float        r;
  402.  
  403. // if the first spawnflag bit is set, the monster will only wake up on
  404. // really seeing the player, not another monster getting angry
  405.  
  406. // spawnflags & 3 is a big hack, because zombie crucified used the first
  407. // spawn flag prior to the ambush flag, and I forgot about it, so the second
  408. // spawn flag works as well
  409.     if (sight_entity_time >= time - 0.1 && !(self.spawnflags & 3) )
  410.     {
  411.         client = sight_entity;
  412.         if (client.enemy == self.enemy)
  413.             return;
  414.     }
  415.     else
  416.     {
  417.         client = checkclient ();
  418.         if (!client)
  419.             return FALSE;    // current check entity isn't in PVS
  420.     }
  421.  
  422.     if (client == self.enemy)
  423.         return FALSE;
  424.  
  425.     if (client.flags & FL_NOTARGET)
  426.         return FALSE;
  427.     if (client.items & IT_INVISIBILITY)
  428.         return FALSE;
  429.     if (client.items & IT_QUAD)    //ws holo
  430.         return FALSE;        //ws
  431.  
  432.     r = range (client);
  433.     if (r == RANGE_FAR)
  434.         return FALSE;
  435.         
  436.     if (!visible (client))
  437.         return FALSE;
  438.  
  439.     if (r == RANGE_NEAR)
  440.     {
  441.         if (client.show_hostile < time && !infront (client))
  442.             return FALSE;
  443.     }
  444.     else if (r == RANGE_MID)
  445.     {
  446.         if ( /* client.show_hostile < time || */ !infront (client))
  447.             return FALSE;
  448.     }
  449.     
  450. //
  451. // got one
  452. //
  453.     self.enemy = client;
  454.     if (self.enemy.classname != "player")
  455.     {
  456.         self.enemy = self.enemy.enemy;
  457.         if (self.enemy.classname != "player")
  458.         {
  459.             self.enemy = world;
  460.             return FALSE;
  461.         }
  462.     }
  463.     
  464.     if(self.flags & FL_FRIENDLY)        //ws... friend
  465.      {
  466.         self.touch=FriendMove;
  467.         self.friend=self.enemy;
  468.         oldself=self;
  469.         self=self.friend;
  470.         player_addfriend(oldself);
  471.         self=oldself;
  472.     }                    //...ws
  473.  
  474.     FoundTarget ();
  475.  
  476.     return TRUE;
  477. };
  478.  
  479.  
  480. //=============================================================================
  481.  
  482. void(float dist) ai_forward =
  483. {
  484.     walkmove (self.angles_y, dist);
  485. };
  486.  
  487. void(float dist) ai_back =
  488. {
  489.     walkmove ( (self.angles_y+180), dist);
  490. };
  491.  
  492.  
  493. /*
  494. =============
  495. ai_pain
  496.  
  497. stagger back a bit
  498. =============
  499. */
  500. void(float dist) ai_pain =
  501. {
  502.     ai_back (dist);
  503. /*
  504.     local float    away;
  505.     
  506.     away = anglemod (vectoyaw (self.origin - self.enemy.origin) 
  507.     + 180*(random()- 0.5) );
  508.     
  509.     walkmove (away, dist);
  510. */
  511. };
  512.  
  513. /*
  514. =============
  515. ai_painforward
  516.  
  517. stagger back a bit
  518. =============
  519. */
  520. void(float dist) ai_painforward =
  521. {
  522.     walkmove (self.ideal_yaw, dist);
  523. };
  524.  
  525. /*
  526. =============
  527. ai_walk
  528.  
  529. The monster is walking it's beat
  530. =============
  531. */
  532. void(float dist) ai_walk =
  533. {
  534.     local vector        mtemp;
  535.     
  536.     movedist = dist;
  537.     
  538.     if (self.classname == "monster_dragon")
  539.     {
  540.         movetogoal (dist);
  541.         return;
  542.     }
  543.     // check for noticing a player
  544.     if (FindTarget ())
  545.         return;
  546.  
  547.     movetogoal (dist);
  548. };
  549.  
  550.  
  551. /*
  552. =============
  553. ai_stand
  554.  
  555. The monster is staying in one place for a while, with slight angle turns
  556. =============
  557. */
  558. void() ai_stand =
  559. {
  560.     local float r;
  561.     if (FindTarget ())
  562.         return;
  563.     
  564.     if (time > self.pausetime)
  565.     {
  566.         if(self.friend) {
  567.             r=range(self.friend);
  568.             if(r==RANGE_MELEE)
  569.                 return;
  570.             else if(r==RANGE_MID)
  571.                 self.th_walk ();
  572.             else
  573.                 self.th_run ();
  574.         }
  575.         return;
  576.     }
  577.     
  578. // change angle slightly
  579.  
  580. };
  581.  
  582. /*
  583. =============
  584. ai_turn
  585.  
  586. don't move, but turn towards ideal_yaw
  587. =============
  588. */
  589. void() ai_turn =
  590. {
  591.     if (FindTarget ())
  592.         return;
  593.     
  594.     ChangeYaw ();
  595. };
  596.  
  597. //=============================================================================
  598.  
  599. /*
  600. =============
  601. ChooseTurn
  602. =============
  603. */
  604. void(vector dest3) ChooseTurn =
  605. {
  606.     local vector    dir, newdir;
  607.     
  608.     dir = self.origin - dest3;
  609.  
  610.     newdir_x = trace_plane_normal_y;
  611.     newdir_y = 0 - trace_plane_normal_x;
  612.     newdir_z = 0;
  613.     
  614.     if (dir * newdir > 0)
  615.     {
  616.         dir_x = 0 - trace_plane_normal_y;
  617.         dir_y = trace_plane_normal_x;
  618.     }
  619.     else
  620.     {
  621.         dir_x = trace_plane_normal_y;
  622.         dir_y = 0 - trace_plane_normal_x;
  623.     }
  624.  
  625.     dir_z = 0;
  626.     self.ideal_yaw = vectoyaw(dir);    
  627. };
  628.  
  629. /*
  630. ============
  631. FacingIdeal
  632.  
  633. ============
  634. */
  635. float() FacingIdeal =
  636. {
  637.     local    float    delta;
  638.     
  639.     delta = anglemod(self.angles_y - self.ideal_yaw);
  640.     if (delta > 45 && delta < 315)
  641.         return FALSE;
  642.     return TRUE;
  643. };
  644.  
  645.  
  646. //=============================================================================
  647.  
  648. float()    WizardCheckAttack;
  649. float()    DogCheckAttack;
  650.  
  651. float() CheckAnyAttack =
  652. {
  653.     if (!enemy_vis)
  654.         return;
  655.     if (self.classname == "monster_army")
  656.         return SoldierCheckAttack ();
  657.     if (self.classname == "monster_ogre")
  658.         return OgreCheckAttack ();
  659.     if (self.classname == "monster_shambler")
  660.         return ShamCheckAttack ();
  661.     if (self.classname == "monster_demon1")
  662.         return DemonCheckAttack ();
  663.     if (self.classname == "monster_dog")
  664.         return DogCheckAttack ();
  665.     if (self.classname == "monster_wizard")
  666.         return WizardCheckAttack ();
  667.     return CheckAttack ();
  668. };
  669.  
  670.  
  671. /*
  672. =============
  673. ai_run_melee
  674.  
  675. Turn and close until within an angle to launch a melee attack
  676. =============
  677. */
  678. void() ai_run_melee =
  679. {
  680.     self.ideal_yaw = enemy_yaw;
  681.     ChangeYaw ();
  682.  
  683.     if (FacingIdeal())
  684.     {
  685.         self.th_melee ();
  686.         self.attack_state = AS_STRAIGHT;
  687.     }
  688. };
  689.  
  690.  
  691. /*
  692. =============
  693. ai_run_missile
  694.  
  695. Turn in place until within an angle to launch a missile attack
  696. =============
  697. */
  698. void() ai_run_missile =
  699. {
  700.     self.ideal_yaw = enemy_yaw;
  701.     ChangeYaw ();
  702.     if (FacingIdeal())
  703.     {
  704.         self.th_missile ();
  705.         self.attack_state = AS_STRAIGHT;
  706.     }
  707. };
  708.  
  709.  
  710. /*
  711. =============
  712. ai_run_slide
  713.  
  714. Strafe sideways, but stay at aproximately the same range
  715. =============
  716. */
  717. void() ai_run_slide =
  718. {
  719.     local float    ofs;
  720.     
  721.     self.ideal_yaw = enemy_yaw;
  722.     ChangeYaw ();
  723.     if (self.lefty)
  724.         ofs = 90;
  725.     else
  726.         ofs = -90;
  727.     
  728.     if (walkmove (self.ideal_yaw + ofs, movedist))
  729.         return;
  730.         
  731.     self.lefty = 1 - self.lefty;
  732.     
  733.     walkmove (self.ideal_yaw - ofs, movedist);
  734. };
  735.  
  736.  
  737. /*
  738. =============
  739. ai_run
  740.  
  741. The monster has an enemy it is trying to kill
  742. =============
  743. */
  744. void(float dist) ai_run =
  745. {
  746.     local    vector    delta;
  747.     local    float    test;
  748.     local    float    axis;
  749.     local    float    direct, ang_rint, ang_floor, ang_ceil;
  750.     
  751.     movedist = dist;
  752. // see if the enemy is dead
  753.     if (self.classname == "monster_dog"
  754.         || self.classname == "monster_shambler"
  755.         || self.classname == "monster_demon") 
  756.         // Those guys are viscious
  757.             test=1;
  758.     else {
  759.         test = (self.enemy.flags & FL_MONSTER) == FL_MONSTER;
  760.         test = test + (self.enemy.classname == "player");
  761.     }
  762.     if (!test || self.enemy.health <= 0)
  763.     {
  764.         self.enemy = world;
  765.     // FIXME: look all around for other targets
  766.         if (self.oldenemy.health > 0)
  767.         {
  768.             self.enemy = self.oldenemy;
  769.             HuntTarget ();
  770.         }
  771.         else
  772.         {
  773.             if (self.friend)
  774.                 if(self.friend.health > 0) {
  775.                     self.enemy = self.friend;
  776.                     HuntTarget();
  777.                 } else {
  778.                     self.friend=world;
  779.                 }
  780.             else if (self.movetarget)
  781.                 self.th_walk ();
  782.             else
  783.                 self.th_stand ();
  784.             return;
  785.         }
  786.     }
  787.  
  788.  
  789. // check knowledge of enemy
  790.     enemy_vis = visible(self.enemy);
  791.     if (enemy_vis)
  792.         self.search_time = time + 5;
  793.  
  794. // Okay, just find our friend
  795.     if(self.enemy == self.friend) {
  796.         // head straight in
  797.         if(range(self.friend) == RANGE_MELEE) {
  798.             self.pausetime=time+1;
  799.             self.th_stand();
  800.         } else
  801.             movetogoal (dist);        // done in C code...
  802.         return;
  803.     }
  804.         
  805.     self.show_hostile = time + 1;        // wake up other monsters
  806.  
  807. // look for other coop players
  808.     if (coop && self.search_time < time)
  809.     {
  810.         if (FindTarget ())
  811.             return;
  812.     }
  813.  
  814.     enemy_infront = infront(self.enemy);
  815.     enemy_range = range(self.enemy);
  816.     enemy_yaw = vectoyaw(self.enemy.origin - self.origin);
  817.     
  818.     if (self.attack_state == AS_MISSILE)
  819.     {
  820. //dprint ("ai_run_missile\n");
  821.         ai_run_missile ();
  822.         return;
  823.     }
  824.     if (self.attack_state == AS_MELEE)
  825.     {
  826. //dprint ("ai_run_melee\n");
  827.         ai_run_melee ();
  828.         return;
  829.     }
  830.  
  831.     if (CheckAnyAttack ())
  832.         return;                    // beginning an attack
  833.         
  834.     if (self.attack_state == AS_SLIDING)
  835.     {
  836.         ai_run_slide ();
  837.         return;
  838.     }
  839.         
  840. // head straight in
  841.     movetogoal (dist);        // done in C code...
  842. };