home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 26 / amigaformatcd26.iso / -screenplay- / otherstuff / adoom_src / p_enemy.c < prev    next >
C/C++ Source or Header  |  1998-03-09  |  37KB  |  2,016 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    Enemy thinking, AI.
  21. //    Action Pointer Functions
  22. //    that are associated with states/frames. 
  23. //
  24. //-----------------------------------------------------------------------------
  25.  
  26. static const char
  27. rcsid[] = "$Id: p_enemy.c,v 1.5 1997/02/03 22:45:11 b1 Exp $";
  28.  
  29. #include <stdlib.h>
  30. #ifdef AMIGA
  31. #include <dos.h>
  32. #endif
  33.  
  34. #include "m_random.h"
  35. #include "i_system.h"
  36.  
  37. #include "doomdef.h"
  38. #include "p_local.h"
  39.  
  40. #include "s_sound.h"
  41.  
  42. #include "g_game.h"
  43.  
  44. // State.
  45. #include "doomstat.h"
  46. #include "r_state.h"
  47.  
  48. // Data.
  49. #include "sounds.h"
  50.  
  51.  
  52.  
  53.  
  54. typedef enum
  55. {
  56.     DI_EAST,
  57.     DI_NORTHEAST,
  58.     DI_NORTH,
  59.     DI_NORTHWEST,
  60.     DI_WEST,
  61.     DI_SOUTHWEST,
  62.     DI_SOUTH,
  63.     DI_SOUTHEAST,
  64.     DI_NODIR,
  65.     NUMDIRS
  66.     
  67. } dirtype_t;
  68.  
  69.  
  70. //
  71. // P_NewChaseDir related LUT.
  72. //
  73. dirtype_t opposite[] =
  74. {
  75.   DI_WEST, DI_SOUTHWEST, DI_SOUTH, DI_SOUTHEAST,
  76.   DI_EAST, DI_NORTHEAST, DI_NORTH, DI_NORTHWEST, DI_NODIR
  77. };
  78.  
  79. dirtype_t diags[] =
  80. {
  81.     DI_NORTHWEST, DI_NORTHEAST, DI_SOUTHWEST, DI_SOUTHEAST
  82. };
  83.  
  84.  
  85.  
  86.  
  87.  
  88. void A_Fall (mobj_t *actor);
  89.  
  90.  
  91. //
  92. // ENEMY THINKING
  93. // Enemies are allways spawned
  94. // with targetplayer = -1, threshold = 0
  95. // Most monsters are spawned unaware of all players,
  96. // but some can be made preaware
  97. //
  98.  
  99.  
  100. //
  101. // Called by P_NoiseAlert.
  102. // Recursively traverse adjacent sectors,
  103. // sound blocking lines cut off traversal.
  104. //
  105.  
  106. mobj_t*        soundtarget;
  107.  
  108. void
  109. P_RecursiveSound
  110. ( sector_t*    sec,
  111.   int        soundblocks )
  112. {
  113.     int        i;
  114.     line_t*    check;
  115.     sector_t*    other;
  116.     
  117.     // wake up all monsters in this sector
  118.     if (sec->validcount == validcount
  119.     && sec->soundtraversed <= soundblocks+1)
  120.     {
  121.     return;        // already flooded
  122.     }
  123.     
  124.     sec->validcount = validcount;
  125.     sec->soundtraversed = soundblocks+1;
  126.     sec->soundtarget = soundtarget;
  127.     
  128.     for (i=0 ;i<sec->linecount ; i++)
  129.     {
  130.     check = sec->lines[i];
  131.     if (! (check->flags & ML_TWOSIDED) )
  132.         continue;
  133.     
  134.     P_LineOpening (check);
  135.  
  136.     if (openrange <= 0)
  137.         continue;    // closed door
  138.     
  139.     if ( sides[ check->sidenum[0] ].sector == sec)
  140.         other = sides[ check->sidenum[1] ] .sector;
  141.     else
  142.         other = sides[ check->sidenum[0] ].sector;
  143.     
  144.     if (check->flags & ML_SOUNDBLOCK)
  145.     {
  146.         if (!soundblocks)
  147.         P_RecursiveSound (other, 1);
  148.     }
  149.     else
  150.         P_RecursiveSound (other, soundblocks);
  151.     }
  152. }
  153.  
  154.  
  155.  
  156. //
  157. // P_NoiseAlert
  158. // If a monster yells at a player,
  159. // it will alert other monsters to the player.
  160. //
  161. void
  162. P_NoiseAlert
  163. ( mobj_t*    target,
  164.   mobj_t*    emmiter )
  165. {
  166.     soundtarget = target;
  167.     validcount++;
  168.     P_RecursiveSound (emmiter->subsector->sector, 0);
  169. }
  170.  
  171.  
  172.  
  173.  
  174. //
  175. // P_CheckMeleeRange
  176. //
  177. boolean P_CheckMeleeRange (mobj_t*    actor)
  178. {
  179.     mobj_t*    pl;
  180.     fixed_t    dist;
  181.     
  182.     if (!actor->target)
  183.     return false;
  184.         
  185.     pl = actor->target;
  186.     dist = P_AproxDistance (pl->x-actor->x, pl->y-actor->y);
  187.  
  188.     if (dist >= MELEERANGE-20*FRACUNIT+pl->info->radius)
  189.     return false;
  190.     
  191.     if (! P_CheckSight (actor, actor->target) )
  192.     return false;
  193.                             
  194.     return true;        
  195. }
  196.  
  197. //
  198. // P_CheckMissileRange
  199. //
  200. boolean P_CheckMissileRange (mobj_t* actor)
  201. {
  202.     fixed_t    dist;
  203.     
  204.     if (! P_CheckSight (actor, actor->target) )
  205.     return false;
  206.     
  207.     if ( actor->flags & MF_JUSTHIT )
  208.     {
  209.     // the target just hit the enemy,
  210.     // so fight back!
  211.     actor->flags &= ~MF_JUSTHIT;
  212.     return true;
  213.     }
  214.     
  215.     if (actor->reactiontime)
  216.     return false;    // do not attack yet
  217.         
  218.     // OPTIMIZE: get this from a global checksight
  219.     dist = P_AproxDistance ( actor->x-actor->target->x,
  220.                  actor->y-actor->target->y) - 64*FRACUNIT;
  221.     
  222.     if (!actor->info->meleestate)
  223.     dist -= 128*FRACUNIT;    // no melee attack, so fire more
  224.  
  225.     dist >>= 16;
  226.  
  227.     if (actor->type == MT_VILE)
  228.     {
  229.     if (dist > 14*64)    
  230.         return false;    // too far away
  231.     }
  232.     
  233.  
  234.     if (actor->type == MT_UNDEAD)
  235.     {
  236.     if (dist < 196)    
  237.         return false;    // close for fist attack
  238.     dist >>= 1;
  239.     }
  240.     
  241.  
  242.     if (actor->type == MT_CYBORG
  243.     || actor->type == MT_SPIDER
  244.     || actor->type == MT_SKULL)
  245.     {
  246.     dist >>= 1;
  247.     }
  248.     
  249.     if (dist > 200)
  250.     dist = 200;
  251.         
  252.     if (actor->type == MT_CYBORG && dist > 160)
  253.     dist = 160;
  254.         
  255.     if (P_Random () < dist)
  256.     return false;
  257.         
  258.     return true;
  259. }
  260.  
  261.  
  262. //
  263. // P_Move
  264. // Move in the current direction,
  265. // returns false if the move is blocked.
  266. //
  267. fixed_t    xspeed[8] = {FRACUNIT,47000,0,-47000,-FRACUNIT,-47000,0,47000};
  268. fixed_t yspeed[8] = {0,47000,FRACUNIT,47000,0,-47000,-FRACUNIT,-47000};
  269.  
  270. #define MAXSPECIALCROSS    20  /* was 8 */
  271.  
  272. extern    line_t*    spechit[MAXSPECIALCROSS];
  273. extern    int    numspechit;
  274.  
  275. boolean P_Move (mobj_t*    actor)
  276. {
  277.     fixed_t    tryx;
  278.     fixed_t    tryy;
  279.     
  280.     line_t*    ld;
  281.     
  282.     // warning: 'catch', 'throw', and 'try'
  283.     // are all C++ reserved words
  284.     boolean    try_ok;
  285.     boolean    good;
  286.         
  287.     if (actor->movedir == DI_NODIR)
  288.     return false;
  289.         
  290.     if ((unsigned)actor->movedir >= 8)
  291.     I_Error ("Weird actor->movedir!");
  292.         
  293.     tryx = actor->x + actor->info->speed*xspeed[actor->movedir];
  294.     tryy = actor->y + actor->info->speed*yspeed[actor->movedir];
  295.  
  296.     try_ok = P_TryMove (actor, tryx, tryy);
  297.  
  298.     if (!try_ok)
  299.     {
  300.     // open any specials
  301.     if (actor->flags & MF_FLOAT && floatok)
  302.     {
  303.         // must adjust height
  304.         if (actor->z < tmfloorz)
  305.         actor->z += FLOATSPEED;
  306.         else
  307.         actor->z -= FLOATSPEED;
  308.  
  309.         actor->flags |= MF_INFLOAT;
  310.         return true;
  311.     }
  312.         
  313.     if (!numspechit)
  314.         return false;
  315.             
  316.     actor->movedir = DI_NODIR;
  317.     good = false;
  318.     while (numspechit--)
  319.     {
  320.         ld = spechit[numspechit];
  321.         // if the special is not a door
  322.         // that can be opened,
  323.         // return false
  324.         if (P_UseSpecialLine (actor, ld,0))
  325.         good = true;
  326.     }
  327.     return good;
  328.     }
  329.     else
  330.     {
  331.     actor->flags &= ~MF_INFLOAT;
  332.     }
  333.     
  334.     
  335.     if (! (actor->flags & MF_FLOAT) )    
  336.     actor->z = actor->floorz;
  337.     return true; 
  338. }
  339.  
  340.  
  341. //
  342. // TryWalk
  343. // Attempts to move actor on
  344. // in its current (ob->moveangle) direction.
  345. // If blocked by either a wall or an actor
  346. // returns FALSE
  347. // If move is either clear or blocked only by a door,
  348. // returns TRUE and sets...
  349. // If a door is in the way,
  350. // an OpenDoor call is made to start it opening.
  351. //
  352. boolean P_TryWalk (mobj_t* actor)
  353. {    
  354.     if (!P_Move (actor))
  355.     {
  356.     return false;
  357.     }
  358.  
  359.     actor->movecount = P_Random()&15;
  360.     return true;
  361. }
  362.  
  363.  
  364.  
  365.  
  366. void P_NewChaseDir (mobj_t*    actor)
  367. {
  368.     fixed_t    deltax;
  369.     fixed_t    deltay;
  370.     
  371.     dirtype_t    d[3];
  372.     
  373.     int        tdir;
  374.     dirtype_t    olddir;
  375.     
  376.     dirtype_t    turnaround;
  377.  
  378.     if (!actor->target)
  379.     I_Error ("P_NewChaseDir: called with no target");
  380.         
  381.     olddir = actor->movedir;
  382.     turnaround=opposite[olddir];
  383.  
  384.     deltax = actor->target->x - actor->x;
  385.     deltay = actor->target->y - actor->y;
  386.  
  387.     if (deltax>10*FRACUNIT)
  388.     d[1]= DI_EAST;
  389.     else if (deltax<-10*FRACUNIT)
  390.     d[1]= DI_WEST;
  391.     else
  392.     d[1]=DI_NODIR;
  393.  
  394.     if (deltay<-10*FRACUNIT)
  395.     d[2]= DI_SOUTH;
  396.     else if (deltay>10*FRACUNIT)
  397.     d[2]= DI_NORTH;
  398.     else
  399.     d[2]=DI_NODIR;
  400.  
  401.     // try direct route
  402.     if (d[1] != DI_NODIR
  403.     && d[2] != DI_NODIR)
  404.     {
  405.     actor->movedir = diags[((deltay<0)<<1)+(deltax>0)];
  406.     if (actor->movedir != turnaround && P_TryWalk(actor))
  407.         return;
  408.     }
  409.  
  410.     // try other directions
  411.     if (P_Random() > 200
  412.     ||  iabs(deltay)>iabs(deltax))
  413.     {
  414.     tdir=d[1];
  415.     d[1]=d[2];
  416.     d[2]=tdir;
  417.     }
  418.  
  419.     if (d[1]==turnaround)
  420.     d[1]=DI_NODIR;
  421.     if (d[2]==turnaround)
  422.     d[2]=DI_NODIR;
  423.     
  424.     if (d[1]!=DI_NODIR)
  425.     {
  426.     actor->movedir = d[1];
  427.     if (P_TryWalk(actor))
  428.     {
  429.         // either moved forward or attacked
  430.         return;
  431.     }
  432.     }
  433.  
  434.     if (d[2]!=DI_NODIR)
  435.     {
  436.     actor->movedir =d[2];
  437.  
  438.     if (P_TryWalk(actor))
  439.         return;
  440.     }
  441.  
  442.     // there is no direct path to the player,
  443.     // so pick another direction.
  444.     if (olddir!=DI_NODIR)
  445.     {
  446.     actor->movedir =olddir;
  447.  
  448.     if (P_TryWalk(actor))
  449.         return;
  450.     }
  451.  
  452.     // randomly determine direction of search
  453.     if (P_Random()&1)     
  454.     {
  455.     for ( tdir=DI_EAST;
  456.           tdir<=DI_SOUTHEAST;
  457.           tdir++ )
  458.     {
  459.         if (tdir!=turnaround)
  460.         {
  461.         actor->movedir =tdir;
  462.         
  463.         if ( P_TryWalk(actor) )
  464.             return;
  465.         }
  466.     }
  467.     }
  468.     else
  469.     {
  470.     for ( tdir=DI_SOUTHEAST;
  471.           tdir != (DI_EAST-1);
  472.           tdir-- )
  473.     {
  474.         if (tdir!=turnaround)
  475.         {
  476.         actor->movedir =tdir;
  477.         
  478.         if ( P_TryWalk(actor) )
  479.             return;
  480.         }
  481.     }
  482.     }
  483.  
  484.     if (turnaround !=  DI_NODIR)
  485.     {
  486.     actor->movedir =turnaround;
  487.     if ( P_TryWalk(actor) )
  488.         return;
  489.     }
  490.  
  491.     actor->movedir = DI_NODIR;    // can not move
  492. }
  493.  
  494.  
  495.  
  496. //
  497. // P_LookForPlayers
  498. // If allaround is false, only look 180 degrees in front.
  499. // Returns true if a player is targeted.
  500. //
  501. boolean
  502. P_LookForPlayers
  503. ( mobj_t*    actor,
  504.   boolean    allaround )
  505. {
  506.     int        c;
  507.     int        stop;
  508.     player_t*    player;
  509.     sector_t*    sector;
  510.     angle_t    an;
  511.     fixed_t    dist;
  512.         
  513.     sector = actor->subsector->sector;
  514.     
  515.     c = 0;
  516.     stop = (actor->lastlook-1)&3;
  517.     
  518.     for ( ; ; actor->lastlook = (actor->lastlook+1)&3 )
  519.     {
  520.     if (!playeringame[actor->lastlook]) {
  521. #ifdef AMIGA
  522.             chkabort ();
  523. #endif
  524.         continue;
  525.         }
  526.             
  527.     if (c++ == 2
  528.         || actor->lastlook == stop)
  529.     {
  530.         // done looking
  531.         return false;    
  532.     }
  533.     
  534.     player = &players[actor->lastlook];
  535.  
  536.     if (player->health <= 0)
  537.         continue;        // dead
  538.  
  539.     if (!P_CheckSight (actor, player->mo))
  540.         continue;        // out of sight
  541.             
  542.     if (!allaround)
  543.     {
  544.         an = R_PointToAngle2 (actor->x,
  545.                   actor->y, 
  546.                   player->mo->x,
  547.                   player->mo->y)
  548.         - actor->angle;
  549.         
  550.         if (an > ANG90 && an < ANG270)
  551.         {
  552.         dist = P_AproxDistance (player->mo->x - actor->x,
  553.                     player->mo->y - actor->y);
  554.         // if real close, react anyway
  555.         if (dist > MELEERANGE)
  556.             continue;    // behind back
  557.         }
  558.     }
  559.         
  560.     actor->target = player->mo;
  561.     return true;
  562.     }
  563.  
  564.     return false;
  565. }
  566.  
  567.  
  568. //
  569. // A_KeenDie
  570. // DOOM II special, map 32.
  571. // Uses special tag 666.
  572. //
  573. void A_KeenDie (mobj_t* mo)
  574. {
  575.     thinker_t*    th;
  576.     mobj_t*    mo2;
  577.     line_t    junk;
  578.  
  579.     A_Fall (mo);
  580.     
  581.     // scan the remaining thinkers
  582.     // to see if all Keens are dead
  583.     for (th = thinkercap.next ; th != &thinkercap ; th=th->next)
  584.     {
  585.     if (th->function.acp1 != (actionf_p1)P_MobjThinker)
  586.         continue;
  587.  
  588.     mo2 = (mobj_t *)th;
  589.     if (mo2 != mo
  590.         && mo2->type == mo->type
  591.         && mo2->health > 0)
  592.     {
  593.         // other Keen not dead
  594.         return;        
  595.     }
  596.     }
  597.  
  598.     junk.tag = 666;
  599.     EV_DoDoor(&junk,open);
  600. }
  601.  
  602.  
  603. //
  604. // ACTION ROUTINES
  605. //
  606.  
  607. //
  608. // A_Look
  609. // Stay in state until a player is sighted.
  610. //
  611. void A_Look (mobj_t* actor)
  612. {
  613.     mobj_t*    targ;
  614.     
  615.     actor->threshold = 0;    // any shot will wake up
  616.     targ = actor->subsector->sector->soundtarget;
  617.  
  618.     if (targ
  619.     && (targ->flags & MF_SHOOTABLE) )
  620.     {
  621.     actor->target = targ;
  622.  
  623.     if ( actor->flags & MF_AMBUSH )
  624.     {
  625.         if (P_CheckSight (actor, actor->target))
  626.         goto seeyou;
  627.     }
  628.     else
  629.         goto seeyou;
  630.     }
  631.     
  632.     
  633.     if (!P_LookForPlayers (actor, false) )
  634.     return;
  635.         
  636.     // go into chase state
  637.   seeyou:
  638.     if (actor->info->seesound)
  639.     {
  640.     int        sound;
  641.         
  642.     switch (actor->info->seesound)
  643.     {
  644.       case sfx_posit1:
  645.       case sfx_posit2:
  646.       case sfx_posit3:
  647.         sound = sfx_posit1+P_Random()%3;
  648.         break;
  649.  
  650.       case sfx_bgsit1:
  651.       case sfx_bgsit2:
  652.         sound = sfx_bgsit1+P_Random()%2;
  653.         break;
  654.  
  655.       default:
  656.         sound = actor->info->seesound;
  657.         break;
  658.     }
  659.  
  660.     if (actor->type==MT_SPIDER
  661.         || actor->type == MT_CYBORG)
  662.     {
  663.         // full volume
  664.         S_StartSound (NULL, sound);
  665.     }
  666.     else
  667.         S_StartSound (actor, sound);
  668.     }
  669.  
  670.     P_SetMobjState (actor, actor->info->seestate);
  671. }
  672.  
  673.  
  674. //
  675. // A_Chase
  676. // Actor has a melee attack,
  677. // so it tries to close as fast as possible
  678. //
  679. void A_Chase (mobj_t*    actor)
  680. {
  681.     int        delta;
  682.  
  683.     if (actor->reactiontime)
  684.     actor->reactiontime--;
  685.                 
  686.  
  687.     // modify target threshold
  688.     if  (actor->threshold)
  689.     {
  690.     if (!actor->target
  691.         || actor->target->health <= 0)
  692.     {
  693.         actor->threshold = 0;
  694.     }
  695.     else
  696.         actor->threshold--;
  697.     }
  698.     
  699.     // turn towards movement direction if not there yet
  700.     if (actor->movedir < 8)
  701.     {
  702.     actor->angle &= (7<<29);
  703.     delta = actor->angle - (actor->movedir << 29);
  704.     
  705.     if (delta > 0)
  706.         actor->angle -= ANG90/2;
  707.     else if (delta < 0)
  708.         actor->angle += ANG90/2;
  709.     }
  710.  
  711.     if (!actor->target
  712.     || !(actor->target->flags&MF_SHOOTABLE))
  713.     {
  714.     // look for a new target
  715.     if (P_LookForPlayers(actor,true))
  716.         return;     // got a new target
  717.     
  718.     P_SetMobjState (actor, actor->info->spawnstate);
  719.     return;
  720.     }
  721.     
  722.     // do not attack twice in a row
  723.     if (actor->flags & MF_JUSTATTACKED)
  724.     {
  725.     actor->flags &= ~MF_JUSTATTACKED;
  726.     if (gameskill != sk_nightmare && !fastparm)
  727.         P_NewChaseDir (actor);
  728.     return;
  729.     }
  730.     
  731.     // check for melee attack
  732.     if (actor->info->meleestate
  733.     && P_CheckMeleeRange (actor))
  734.     {
  735.     if (actor->info->attacksound)
  736.         S_StartSound (actor, actor->info->attacksound);
  737.  
  738.     P_SetMobjState (actor, actor->info->meleestate);
  739.     return;
  740.     }
  741.     
  742.     // check for missile attack
  743.     if (actor->info->missilestate)
  744.     {
  745.     if (gameskill < sk_nightmare
  746.         && !fastparm && actor->movecount)
  747.     {
  748.         goto nomissile;
  749.     }
  750.     
  751.     if (!P_CheckMissileRange (actor))
  752.         goto nomissile;
  753.     
  754.     P_SetMobjState (actor, actor->info->missilestate);
  755.     actor->flags |= MF_JUSTATTACKED;
  756.     return;
  757.     }
  758.  
  759.     // ?
  760.   nomissile:
  761.     // possibly choose another target
  762.     if (netgame
  763.     && !actor->threshold
  764.     && !P_CheckSight (actor, actor->target) )
  765.     {
  766.     if (P_LookForPlayers(actor,true))
  767.         return;    // got a new target
  768.     }
  769.     
  770.     // chase towards player
  771.     if (--actor->movecount<0
  772.     || !P_Move (actor))
  773.     {
  774.     P_NewChaseDir (actor);
  775.     }
  776.     
  777.     // make active sound
  778.     if (actor->info->activesound
  779.     && P_Random () < 3)
  780.     {
  781.     S_StartSound (actor, actor->info->activesound);
  782.     }
  783. }
  784.  
  785.  
  786. //
  787. // A_FaceTarget
  788. //
  789. void A_FaceTarget (mobj_t* actor)
  790. {    
  791.     if (!actor->target)
  792.     return;
  793.     
  794.     actor->flags &= ~MF_AMBUSH;
  795.     
  796.     actor->angle = R_PointToAngle2 (actor->x,
  797.                     actor->y,
  798.                     actor->target->x,
  799.                     actor->target->y);
  800.     
  801.     if (actor->target->flags & MF_SHADOW)
  802.     actor->angle += (P_Random()-P_Random())<<21;
  803. }
  804.  
  805.  
  806. //
  807. // A_PosAttack
  808. //
  809. void A_PosAttack (mobj_t* actor)
  810. {
  811.     int        angle;
  812.     int        damage;
  813.     int        slope;
  814.     
  815.     if (!actor->target)
  816.     return;
  817.         
  818.     A_FaceTarget (actor);
  819.     angle = actor->angle;
  820.     slope = P_AimLineAttack (actor, angle, MISSILERANGE);
  821.  
  822.     S_StartSound (actor, sfx_pistol);
  823.     angle += (P_Random()-P_Random())<<20;
  824.     damage = ((P_Random()%5)+1)*3;
  825.     P_LineAttack (actor, angle, MISSILERANGE, slope, damage);
  826. }
  827.  
  828. void A_SPosAttack (mobj_t* actor)
  829. {
  830.     int        i;
  831.     int        angle;
  832.     int        bangle;
  833.     int        damage;
  834.     int        slope;
  835.     
  836.     if (!actor->target)
  837.     return;
  838.  
  839.     S_StartSound (actor, sfx_shotgn);
  840.     A_FaceTarget (actor);
  841.     bangle = actor->angle;
  842.     slope = P_AimLineAttack (actor, bangle, MISSILERANGE);
  843.  
  844.     for (i=0 ; i<3 ; i++)
  845.     {
  846.     angle = bangle + ((P_Random()-P_Random())<<20);
  847.     damage = ((P_Random()%5)+1)*3;
  848.     P_LineAttack (actor, angle, MISSILERANGE, slope, damage);
  849.     }
  850. }
  851.  
  852. void A_CPosAttack (mobj_t* actor)
  853. {
  854.     int        angle;
  855.     int        bangle;
  856.     int        damage;
  857.     int        slope;
  858.     
  859.     if (!actor->target)
  860.     return;
  861.  
  862.     S_StartSound (actor, sfx_shotgn);
  863.     A_FaceTarget (actor);
  864.     bangle = actor->angle;
  865.     slope = P_AimLineAttack (actor, bangle, MISSILERANGE);
  866.  
  867.     angle = bangle + ((P_Random()-P_Random())<<20);
  868.     damage = ((P_Random()%5)+1)*3;
  869.     P_LineAttack (actor, angle, MISSILERANGE, slope, damage);
  870. }
  871.  
  872. void A_CPosRefire (mobj_t* actor)
  873. {    
  874.     // keep firing unless target got out of sight
  875.     A_FaceTarget (actor);
  876.  
  877.     if (P_Random () < 40)
  878.     return;
  879.  
  880.     if (!actor->target
  881.     || actor->target->health <= 0
  882.     || !P_CheckSight (actor, actor->target) )
  883.     {
  884.     P_SetMobjState (actor, actor->info->seestate);
  885.     }
  886. }
  887.  
  888.  
  889. void A_SpidRefire (mobj_t* actor)
  890. {    
  891.     // keep firing unless target got out of sight
  892.     A_FaceTarget (actor);
  893.  
  894.     if (P_Random () < 10)
  895.     return;
  896.  
  897.     if (!actor->target
  898.     || actor->target->health <= 0
  899.     || !P_CheckSight (actor, actor->target) )
  900.     {
  901.     P_SetMobjState (actor, actor->info->seestate);
  902.     }
  903. }
  904.  
  905. void A_BspiAttack (mobj_t *actor)
  906. {    
  907.     if (!actor->target)
  908.     return;
  909.         
  910.     A_FaceTarget (actor);
  911.  
  912.     // launch a missile
  913.     P_SpawnMissile (actor, actor->target, MT_ARACHPLAZ);
  914. }
  915.  
  916.  
  917. //
  918. // A_TroopAttack
  919. //
  920. void A_TroopAttack (mobj_t* actor)
  921. {
  922.     int        damage;
  923.     
  924.     if (!actor->target)
  925.     return;
  926.         
  927.     A_FaceTarget (actor);
  928.     if (P_CheckMeleeRange (actor))
  929.     {
  930.     S_StartSound (actor, sfx_claw);
  931.     damage = (P_Random()%8+1)*3;
  932.     P_DamageMobj (actor->target, actor, actor, damage);
  933.     return;
  934.     }
  935.  
  936.     
  937.     // launch a missile
  938.     P_SpawnMissile (actor, actor->target, MT_TROOPSHOT);
  939. }
  940.  
  941.  
  942. void A_SargAttack (mobj_t* actor)
  943. {
  944.     int        damage;
  945.  
  946.     if (!actor->target)
  947.     return;
  948.         
  949.     A_FaceTarget (actor);
  950.     if (P_CheckMeleeRange (actor))
  951.     {
  952.     damage = ((P_Random()%10)+1)*4;
  953.     P_DamageMobj (actor->target, actor, actor, damage);
  954.     }
  955. }
  956.  
  957. void A_HeadAttack (mobj_t* actor)
  958. {
  959.     int        damage;
  960.     
  961.     if (!actor->target)
  962.     return;
  963.         
  964.     A_FaceTarget (actor);
  965.     if (P_CheckMeleeRange (actor))
  966.     {
  967.     damage = (P_Random()%6+1)*10;
  968.     P_DamageMobj (actor->target, actor, actor, damage);
  969.     return;
  970.     }
  971.     
  972.     // launch a missile
  973.     P_SpawnMissile (actor, actor->target, MT_HEADSHOT);
  974. }
  975.  
  976. void A_CyberAttack (mobj_t* actor)
  977. {    
  978.     if (!actor->target)
  979.     return;
  980.         
  981.     A_FaceTarget (actor);
  982.     P_SpawnMissile (actor, actor->target, MT_ROCKET);
  983. }
  984.  
  985.  
  986. void A_BruisAttack (mobj_t* actor)
  987. {
  988.     int        damage;
  989.     
  990.     if (!actor->target)
  991.     return;
  992.         
  993.     if (P_CheckMeleeRange (actor))
  994.     {
  995.     S_StartSound (actor, sfx_claw);
  996.     damage = (P_Random()%8+1)*10;
  997.     P_DamageMobj (actor->target, actor, actor, damage);
  998.     return;
  999.     }
  1000.     
  1001.     // launch a missile
  1002.     P_SpawnMissile (actor, actor->target, MT_BRUISERSHOT);
  1003. }
  1004.  
  1005.  
  1006. //
  1007. // A_SkelMissile
  1008. //
  1009. void A_SkelMissile (mobj_t* actor)
  1010. {    
  1011.     mobj_t*    mo;
  1012.     
  1013.     if (!actor->target)
  1014.     return;
  1015.         
  1016.     A_FaceTarget (actor);
  1017.     actor->z += 16*FRACUNIT;    // so missile spawns higher
  1018.     mo = P_SpawnMissile (actor, actor->target, MT_TRACER);
  1019.     actor->z -= 16*FRACUNIT;    // back to normal
  1020.  
  1021.     mo->x += mo->momx;
  1022.     mo->y += mo->momy;
  1023.     mo->tracer = actor->target;
  1024. }
  1025.  
  1026. int    TRACEANGLE = 0xc000000;
  1027.  
  1028. void A_Tracer (mobj_t* actor)
  1029. {
  1030.     angle_t    exact;
  1031.     fixed_t    dist;
  1032.     fixed_t    slope;
  1033.     mobj_t*    dest;
  1034.     mobj_t*    th;
  1035.         
  1036.     if (gametic & 3)
  1037.     return;
  1038.     
  1039.     // spawn a puff of smoke behind the rocket        
  1040.     P_SpawnPuff (actor->x, actor->y, actor->z);
  1041.     
  1042.     th = P_SpawnMobj (actor->x-actor->momx,
  1043.               actor->y-actor->momy,
  1044.               actor->z, MT_SMOKE);
  1045.     
  1046.     th->momz = FRACUNIT;
  1047.     th->tics -= P_Random()&3;
  1048.     if (th->tics < 1)
  1049.     th->tics = 1;
  1050.     
  1051.     // adjust direction
  1052.     dest = actor->tracer;
  1053.     
  1054.     if (!dest || dest->health <= 0)
  1055.     return;
  1056.     
  1057.     // change angle    
  1058.     exact = R_PointToAngle2 (actor->x,
  1059.                  actor->y,
  1060.                  dest->x,
  1061.                  dest->y);
  1062.  
  1063.     if (exact != actor->angle)
  1064.     {
  1065.     if (exact - actor->angle > 0x80000000)
  1066.     {
  1067.         actor->angle -= TRACEANGLE;
  1068.         if (exact - actor->angle < 0x80000000)
  1069.         actor->angle = exact;
  1070.     }
  1071.     else
  1072.     {
  1073.         actor->angle += TRACEANGLE;
  1074.         if (exact - actor->angle > 0x80000000)
  1075.         actor->angle = exact;
  1076.     }
  1077.     }
  1078.     
  1079.     exact = actor->angle>>ANGLETOFINESHIFT;
  1080.     actor->momx = FixedMul (actor->info->speed, finecosine[exact]);
  1081.     actor->momy = FixedMul (actor->info->speed, finesine[exact]);
  1082.     
  1083.     // change slope
  1084.     dist = P_AproxDistance (dest->x - actor->x,
  1085.                 dest->y - actor->y);
  1086.     
  1087.     dist = dist / actor->info->speed;
  1088.  
  1089.     if (dist < 1)
  1090.     dist = 1;
  1091.     slope = (dest->z+40*FRACUNIT - actor->z) / dist;
  1092.  
  1093.     if (slope < actor->momz)
  1094.     actor->momz -= FRACUNIT/8;
  1095.     else
  1096.     actor->momz += FRACUNIT/8;
  1097. }
  1098.  
  1099.  
  1100. void A_SkelWhoosh (mobj_t*    actor)
  1101. {
  1102.     if (!actor->target)
  1103.     return;
  1104.     A_FaceTarget (actor);
  1105.     S_StartSound (actor,sfx_skeswg);
  1106. }
  1107.  
  1108. void A_SkelFist (mobj_t*    actor)
  1109. {
  1110.     int        damage;
  1111.  
  1112.     if (!actor->target)
  1113.     return;
  1114.         
  1115.     A_FaceTarget (actor);
  1116.     
  1117.     if (P_CheckMeleeRange (actor))
  1118.     {
  1119.     damage = ((P_Random()%10)+1)*6;
  1120.     S_StartSound (actor, sfx_skepch);
  1121.     P_DamageMobj (actor->target, actor, actor, damage);
  1122.     }
  1123. }
  1124.  
  1125.  
  1126.  
  1127. //
  1128. // PIT_VileCheck
  1129. // Detect a corpse that could be raised.
  1130. //
  1131. mobj_t*        corpsehit;
  1132. mobj_t*        vileobj;
  1133. fixed_t        viletryx;
  1134. fixed_t        viletryy;
  1135.  
  1136. boolean PIT_VileCheck (mobj_t*    thing)
  1137. {
  1138.     int        maxdist;
  1139.     boolean    check;
  1140.     
  1141.     if (!(thing->flags & MF_CORPSE) )
  1142.     return true;    // not a monster
  1143.     
  1144.     if (thing->tics != -1)
  1145.     return true;    // not lying still yet
  1146.     
  1147.     if (thing->info->raisestate == S_NULL)
  1148.     return true;    // monster doesn't have a raise state
  1149.     
  1150.     maxdist = thing->info->radius + mobjinfo[MT_VILE].radius;
  1151.     
  1152.     if ( iabs(thing->x - viletryx) > maxdist
  1153.      || iabs(thing->y - viletryy) > maxdist )
  1154.     return true;        // not actually touching
  1155.         
  1156.     corpsehit = thing;
  1157.     corpsehit->momx = corpsehit->momy = 0;
  1158.     corpsehit->height <<= 2;
  1159.     check = P_CheckPosition (corpsehit, corpsehit->x, corpsehit->y);
  1160.     corpsehit->height >>= 2;
  1161.  
  1162.     if (!check)
  1163.     return true;        // doesn't fit here
  1164.         
  1165.     return false;        // got one, so stop checking
  1166. }
  1167.  
  1168.  
  1169.  
  1170. //
  1171. // A_VileChase
  1172. // Check for ressurecting a body
  1173. //
  1174. void A_VileChase (mobj_t* actor)
  1175. {
  1176.     int            xl;
  1177.     int            xh;
  1178.     int            yl;
  1179.     int            yh;
  1180.     
  1181.     int            bx;
  1182.     int            by;
  1183.  
  1184.     mobjinfo_t*        info;
  1185.     mobj_t*        temp;
  1186.     
  1187.     if (actor->movedir != DI_NODIR)
  1188.     {
  1189.     // check for corpses to raise
  1190.     viletryx =
  1191.         actor->x + actor->info->speed*xspeed[actor->movedir];
  1192.     viletryy =
  1193.         actor->y + actor->info->speed*yspeed[actor->movedir];
  1194.  
  1195.     xl = (viletryx - bmaporgx - MAXRADIUS*2)>>MAPBLOCKSHIFT;
  1196.     xh = (viletryx - bmaporgx + MAXRADIUS*2)>>MAPBLOCKSHIFT;
  1197.     yl = (viletryy - bmaporgy - MAXRADIUS*2)>>MAPBLOCKSHIFT;
  1198.     yh = (viletryy - bmaporgy + MAXRADIUS*2)>>MAPBLOCKSHIFT;
  1199.     
  1200.     vileobj = actor;
  1201.     for (bx=xl ; bx<=xh ; bx++)
  1202.     {
  1203.         for (by=yl ; by<=yh ; by++)
  1204.         {
  1205.         // Call PIT_VileCheck to check
  1206.         // whether object is a corpse
  1207.         // that canbe raised.
  1208.         if (!P_BlockThingsIterator(bx,by,PIT_VileCheck))
  1209.         {
  1210.             // got one!
  1211.             temp = actor->target;
  1212.             actor->target = corpsehit;
  1213.             A_FaceTarget (actor);
  1214.             actor->target = temp;
  1215.                     
  1216.             P_SetMobjState (actor, S_VILE_HEAL1);
  1217.             S_StartSound (corpsehit, sfx_slop);
  1218.             info = corpsehit->info;
  1219.             
  1220.             P_SetMobjState (corpsehit,info->raisestate);
  1221.             corpsehit->height <<= 2;
  1222.             corpsehit->flags = info->flags;
  1223.             corpsehit->health = info->spawnhealth;
  1224.             corpsehit->target = NULL;
  1225.  
  1226.             return;
  1227.         }
  1228.         }
  1229.     }
  1230.     }
  1231.  
  1232.     // Return to normal attack.
  1233.     A_Chase (actor);
  1234. }
  1235.  
  1236.  
  1237. //
  1238. // A_VileStart
  1239. //
  1240. void A_VileStart (mobj_t* actor)
  1241. {
  1242.     S_StartSound (actor, sfx_vilatk);
  1243. }
  1244.  
  1245.  
  1246. //
  1247. // A_Fire
  1248. // Keep fire in front of player unless out of sight
  1249. //
  1250. void A_Fire (mobj_t* actor);
  1251.  
  1252. void A_StartFire (mobj_t* actor)
  1253. {
  1254.     S_StartSound(actor,sfx_flamst);
  1255.     A_Fire(actor);
  1256. }
  1257.  
  1258. void A_FireCrackle (mobj_t* actor)
  1259. {
  1260.     S_StartSound(actor,sfx_flame);
  1261.     A_Fire(actor);
  1262. }
  1263.  
  1264. void A_Fire (mobj_t* actor)
  1265. {
  1266.     mobj_t*    dest;
  1267.     unsigned    an;
  1268.         
  1269.     dest = actor->tracer;
  1270.     if (!dest)
  1271.     return;
  1272.         
  1273.     // don't move it if the vile lost sight
  1274.     if (!P_CheckSight (actor->target, dest) )
  1275.     return;
  1276.  
  1277.     an = dest->angle >> ANGLETOFINESHIFT;
  1278.  
  1279.     P_UnsetThingPosition (actor);
  1280.     actor->x = dest->x + FixedMul (24*FRACUNIT, finecosine[an]);
  1281.     actor->y = dest->y + FixedMul (24*FRACUNIT, finesine[an]);
  1282.     actor->z = dest->z;
  1283.     P_SetThingPosition (actor);
  1284. }
  1285.  
  1286.  
  1287.  
  1288. //
  1289. // A_VileTarget
  1290. // Spawn the hellfire
  1291. //
  1292. void A_VileTarget (mobj_t*    actor)
  1293. {
  1294.     mobj_t*    fog;
  1295.     
  1296.     if (!actor->target)
  1297.     return;
  1298.  
  1299.     A_FaceTarget (actor);
  1300.  
  1301.     fog = P_SpawnMobj (actor->target->x,
  1302.                actor->target->x,
  1303.                actor->target->z, MT_FIRE);
  1304.     
  1305.     actor->tracer = fog;
  1306.     fog->target = actor;
  1307.     fog->tracer = actor->target;
  1308.     A_Fire (fog);
  1309. }
  1310.  
  1311.  
  1312.  
  1313.  
  1314. //
  1315. // A_VileAttack
  1316. //
  1317. void A_VileAttack (mobj_t* actor)
  1318. {    
  1319.     mobj_t*    fire;
  1320.     int        an;
  1321.     
  1322.     if (!actor->target)
  1323.     return;
  1324.     
  1325.     A_FaceTarget (actor);
  1326.  
  1327.     if (!P_CheckSight (actor, actor->target) )
  1328.     return;
  1329.  
  1330.     S_StartSound (actor, sfx_barexp);
  1331.     P_DamageMobj (actor->target, actor, actor, 20);
  1332.     actor->target->momz = 1000*FRACUNIT/actor->target->info->mass;
  1333.     
  1334.     an = actor->angle >> ANGLETOFINESHIFT;
  1335.  
  1336.     fire = actor->tracer;
  1337.  
  1338.     if (!fire)
  1339.     return;
  1340.         
  1341.     // move the fire between the vile and the player
  1342.     fire->x = actor->target->x - FixedMul (24*FRACUNIT, finecosine[an]);
  1343.     fire->y = actor->target->y - FixedMul (24*FRACUNIT, finesine[an]);    
  1344.     P_RadiusAttack (fire, actor, 70 );
  1345. }
  1346.  
  1347.  
  1348.  
  1349.  
  1350. //
  1351. // Mancubus attack,
  1352. // firing three missiles (bruisers)
  1353. // in three different directions?
  1354. // Doesn't look like it. 
  1355. //
  1356. #define    FATSPREAD    (ANG90/8)
  1357.  
  1358. void A_FatRaise (mobj_t *actor)
  1359. {
  1360.     A_FaceTarget (actor);
  1361.     S_StartSound (actor, sfx_manatk);
  1362. }
  1363.  
  1364.  
  1365. void A_FatAttack1 (mobj_t* actor)
  1366. {
  1367.     mobj_t*    mo;
  1368.     int        an;
  1369.     
  1370.     A_FaceTarget (actor);
  1371.     // Change direction  to ...
  1372.     actor->angle += FATSPREAD;
  1373.     P_SpawnMissile (actor, actor->target, MT_FATSHOT);
  1374.  
  1375.     mo = P_SpawnMissile (actor, actor->target, MT_FATSHOT);
  1376.     mo->angle += FATSPREAD;
  1377.     an = mo->angle >> ANGLETOFINESHIFT;
  1378.     mo->momx = FixedMul (mo->info->speed, finecosine[an]);
  1379.     mo->momy = FixedMul (mo->info->speed, finesine[an]);
  1380. }
  1381.  
  1382. void A_FatAttack2 (mobj_t* actor)
  1383. {
  1384.     mobj_t*    mo;
  1385.     int        an;
  1386.  
  1387.     A_FaceTarget (actor);
  1388.     // Now here choose opposite deviation.
  1389.     actor->angle -= FATSPREAD;
  1390.     P_SpawnMissile (actor, actor->target, MT_FATSHOT);
  1391.  
  1392.     mo = P_SpawnMissile (actor, actor->target, MT_FATSHOT);
  1393.     mo->angle -= FATSPREAD*2;
  1394.     an = mo->angle >> ANGLETOFINESHIFT;
  1395.     mo->momx = FixedMul (mo->info->speed, finecosine[an]);
  1396.     mo->momy = FixedMul (mo->info->speed, finesine[an]);
  1397. }
  1398.  
  1399. void A_FatAttack3 (mobj_t*    actor)
  1400. {
  1401.     mobj_t*    mo;
  1402.     int        an;
  1403.  
  1404.     A_FaceTarget (actor);
  1405.     
  1406.     mo = P_SpawnMissile (actor, actor->target, MT_FATSHOT);
  1407.     mo->angle -= FATSPREAD/2;
  1408.     an = mo->angle >> ANGLETOFINESHIFT;
  1409.     mo->momx = FixedMul (mo->info->speed, finecosine[an]);
  1410.     mo->momy = FixedMul (mo->info->speed, finesine[an]);
  1411.  
  1412.     mo = P_SpawnMissile (actor, actor->target, MT_FATSHOT);
  1413.     mo->angle += FATSPREAD/2;
  1414.     an = mo->angle >> ANGLETOFINESHIFT;
  1415.     mo->momx = FixedMul (mo->info->speed, finecosine[an]);
  1416.     mo->momy = FixedMul (mo->info->speed, finesine[an]);
  1417. }
  1418.  
  1419.  
  1420. //
  1421. // SkullAttack
  1422. // Fly at the player like a missile.
  1423. //
  1424. #define    SKULLSPEED        (20*FRACUNIT)
  1425.  
  1426. void A_SkullAttack (mobj_t* actor)
  1427. {
  1428.     mobj_t*        dest;
  1429.     angle_t        an;
  1430.     int            dist;
  1431.  
  1432.     if (!actor->target)
  1433.     return;
  1434.         
  1435.     dest = actor->target;    
  1436.     actor->flags |= MF_SKULLFLY;
  1437.  
  1438.     S_StartSound (actor, actor->info->attacksound);
  1439.     A_FaceTarget (actor);
  1440.     an = actor->angle >> ANGLETOFINESHIFT;
  1441.     actor->momx = FixedMul (SKULLSPEED, finecosine[an]);
  1442.     actor->momy = FixedMul (SKULLSPEED, finesine[an]);
  1443.     dist = P_AproxDistance (dest->x - actor->x, dest->y - actor->y);
  1444.     dist = dist / SKULLSPEED;
  1445.     
  1446.     if (dist < 1)
  1447.     dist = 1;
  1448.     actor->momz = (dest->z+(dest->height>>1) - actor->z) / dist;
  1449. }
  1450.  
  1451.  
  1452. //
  1453. // A_PainShootSkull
  1454. // Spawn a lost soul and launch it at the target
  1455. //
  1456. void
  1457. A_PainShootSkull
  1458. ( mobj_t*    actor,
  1459.   angle_t    angle )
  1460. {
  1461.     fixed_t    x;
  1462.     fixed_t    y;
  1463.     fixed_t    z;
  1464.     
  1465.     mobj_t*    newmobj;
  1466.     angle_t    an;
  1467.     int        prestep;
  1468.     int        count;
  1469.     thinker_t*    currentthinker;
  1470.  
  1471.     // count total number of skull currently on the level
  1472.     count = 0;
  1473.  
  1474.     currentthinker = thinkercap.next;
  1475.     while (currentthinker != &thinkercap)
  1476.     {
  1477.     if (   (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker)
  1478.         && ((mobj_t *)currentthinker)->type == MT_SKULL)
  1479.         count++;
  1480.     currentthinker = currentthinker->next;
  1481.     }
  1482.  
  1483.     // if there are allready 20 skulls on the level,
  1484.     // don't spit another one
  1485.     if (count > 20)
  1486.     return;
  1487.  
  1488.  
  1489.     // okay, there's playe for another one
  1490.     an = angle >> ANGLETOFINESHIFT;
  1491.     
  1492.     prestep =
  1493.     4*FRACUNIT
  1494.     + 3*(actor->info->radius + mobjinfo[MT_SKULL].radius)/2;
  1495.     
  1496.     x = actor->x + FixedMul (prestep, finecosine[an]);
  1497.     y = actor->y + FixedMul (prestep, finesine[an]);
  1498.     z = actor->z + 8*FRACUNIT;
  1499.         
  1500.     newmobj = P_SpawnMobj (x , y, z, MT_SKULL);
  1501.  
  1502.     // Check for movements.
  1503.     if (!P_TryMove (newmobj, newmobj->x, newmobj->y))
  1504.     {
  1505.     // kill it immediately
  1506.     P_DamageMobj (newmobj,actor,actor,10000);    
  1507.     return;
  1508.     }
  1509.         
  1510.     newmobj->target = actor->target;
  1511.     A_SkullAttack (newmobj);
  1512. }
  1513.  
  1514.  
  1515. //
  1516. // A_PainAttack
  1517. // Spawn a lost soul and launch it at the target
  1518. // 
  1519. void A_PainAttack (mobj_t* actor)
  1520. {
  1521.     if (!actor->target)
  1522.     return;
  1523.  
  1524.     A_FaceTarget (actor);
  1525.     A_PainShootSkull (actor, actor->angle);
  1526. }
  1527.  
  1528.  
  1529. void A_PainDie (mobj_t* actor)
  1530. {
  1531.     A_Fall (actor);
  1532.     A_PainShootSkull (actor, actor->angle+ANG90);
  1533.     A_PainShootSkull (actor, actor->angle+ANG180);
  1534.     A_PainShootSkull (actor, actor->angle+ANG270);
  1535. }
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542. void A_Scream (mobj_t* actor)
  1543. {
  1544.     int        sound;
  1545.     
  1546.     switch (actor->info->deathsound)
  1547.     {
  1548.       case 0:
  1549.     return;
  1550.         
  1551.       case sfx_podth1:
  1552.       case sfx_podth2:
  1553.       case sfx_podth3:
  1554.     sound = sfx_podth1 + P_Random ()%3;
  1555.     break;
  1556.         
  1557.       case sfx_bgdth1:
  1558.       case sfx_bgdth2:
  1559.     sound = sfx_bgdth1 + P_Random ()%2;
  1560.     break;
  1561.     
  1562.       default:
  1563.     sound = actor->info->deathsound;
  1564.     break;
  1565.     }
  1566.  
  1567.     // Check for bosses.
  1568.     if (actor->type==MT_SPIDER
  1569.     || actor->type == MT_CYBORG)
  1570.     {
  1571.     // full volume
  1572.     S_StartSound (NULL, sound);
  1573.     }
  1574.     else
  1575.     S_StartSound (actor, sound);
  1576. }
  1577.  
  1578.  
  1579. void A_XScream (mobj_t* actor)
  1580. {
  1581.     S_StartSound (actor, sfx_slop);    
  1582. }
  1583.  
  1584. void A_Pain (mobj_t* actor)
  1585. {
  1586.     if (actor->info->painsound)
  1587.     S_StartSound (actor, actor->info->painsound);    
  1588. }
  1589.  
  1590.  
  1591.  
  1592. void A_Fall (mobj_t *actor)
  1593. {
  1594.     // actor is on ground, it can be walked over
  1595.     actor->flags &= ~MF_SOLID;
  1596.  
  1597.     // So change this if corpse objects
  1598.     // are meant to be obstacles.
  1599. }
  1600.  
  1601.  
  1602. //
  1603. // A_Explode
  1604. //
  1605. void A_Explode (mobj_t* thingy)
  1606. {
  1607.     P_RadiusAttack ( thingy, thingy->target, 128 );
  1608. }
  1609.  
  1610.  
  1611. //
  1612. // A_BossDeath
  1613. // Possibly trigger special effects
  1614. // if on first boss level
  1615. //
  1616. void A_BossDeath (mobj_t* mo)
  1617. {
  1618.     thinker_t*    th;
  1619.     mobj_t*    mo2;
  1620.     line_t    junk;
  1621.     int        i;
  1622.         
  1623.     if ( gamemode == commercial)
  1624.     {
  1625.     if (gamemap != 7)
  1626.         return;
  1627.         
  1628.     if ((mo->type != MT_FATSO)
  1629.         && (mo->type != MT_BABY))
  1630.         return;
  1631.     }
  1632.     else
  1633.     {
  1634.     switch(gameepisode)
  1635.     {
  1636.       case 1:
  1637.         if (gamemap != 8)
  1638.         return;
  1639.  
  1640.         if (mo->type != MT_BRUISER)
  1641.         return;
  1642.         break;
  1643.         
  1644.       case 2:
  1645.         if (gamemap != 8)
  1646.         return;
  1647.  
  1648.         if (mo->type != MT_CYBORG)
  1649.         return;
  1650.         break;
  1651.         
  1652.       case 3:
  1653.         if (gamemap != 8)
  1654.         return;
  1655.         
  1656.         if (mo->type != MT_SPIDER)
  1657.         return;
  1658.         
  1659.         break;
  1660.         
  1661.       case 4:
  1662.         switch(gamemap)
  1663.         {
  1664.           case 6:
  1665.         if (mo->type != MT_CYBORG)
  1666.             return;
  1667.         break;
  1668.         
  1669.           case 8: 
  1670.         if (mo->type != MT_SPIDER)
  1671.             return;
  1672.         break;
  1673.         
  1674.           default:
  1675.         return;
  1676.         break;
  1677.         }
  1678.         break;
  1679.         
  1680.       default:
  1681.         if (gamemap != 8)
  1682.         return;
  1683.         break;
  1684.     }
  1685.         
  1686.     }
  1687.  
  1688.     
  1689.     // make sure there is a player alive for victory
  1690.     for (i=0 ; i<MAXPLAYERS ; i++)
  1691.     if (playeringame[i] && players[i].health > 0)
  1692.         break;
  1693.     
  1694.     if (i==MAXPLAYERS)
  1695.     return;    // no one left alive, so do not end game
  1696.     
  1697.     // scan the remaining thinkers to see
  1698.     // if all bosses are dead
  1699.     for (th = thinkercap.next ; th != &thinkercap ; th=th->next)
  1700.     {
  1701.     if (th->function.acp1 != (actionf_p1)P_MobjThinker)
  1702.         continue;
  1703.     
  1704.     mo2 = (mobj_t *)th;
  1705.     if (mo2 != mo
  1706.         && mo2->type == mo->type
  1707.         && mo2->health > 0)
  1708.     {
  1709.         // other boss not dead
  1710.         return;
  1711.     }
  1712.     }
  1713.     
  1714.     // victory!
  1715.     if ( gamemode == commercial)
  1716.     {
  1717.     if (gamemap == 7)
  1718.     {
  1719.         if (mo->type == MT_FATSO)
  1720.         {
  1721.         junk.tag = 666;
  1722.         EV_DoFloor(&junk,lowerFloorToLowest);
  1723.         return;
  1724.         }
  1725.         
  1726.         if (mo->type == MT_BABY)
  1727.         {
  1728.         junk.tag = 667;
  1729.         EV_DoFloor(&junk,raiseToTexture);
  1730.         return;
  1731.         }
  1732.     }
  1733.     }
  1734.     else
  1735.     {
  1736.     switch(gameepisode)
  1737.     {
  1738.       case 1:
  1739.         junk.tag = 666;
  1740.         EV_DoFloor (&junk, lowerFloorToLowest);
  1741.         return;
  1742.         break;
  1743.         
  1744.       case 4:
  1745.         switch(gamemap)
  1746.         {
  1747.           case 6:
  1748.         junk.tag = 666;
  1749.         EV_DoDoor (&junk, blazeOpen);
  1750.         return;
  1751.         break;
  1752.         
  1753.           case 8:
  1754.         junk.tag = 666;
  1755.         EV_DoFloor (&junk, lowerFloorToLowest);
  1756.         return;
  1757.         break;
  1758.         }
  1759.     }
  1760.     }
  1761.     
  1762.     G_ExitLevel ();
  1763. }
  1764.  
  1765.  
  1766. void A_Hoof (mobj_t* mo)
  1767. {
  1768.     S_StartSound (mo, sfx_hoof);
  1769.     A_Chase (mo);
  1770. }
  1771.  
  1772. void A_Metal (mobj_t* mo)
  1773. {
  1774.     S_StartSound (mo, sfx_metal);
  1775.     A_Chase (mo);
  1776. }
  1777.  
  1778. void A_BabyMetal (mobj_t* mo)
  1779. {
  1780.     S_StartSound (mo, sfx_bspwlk);
  1781.     A_Chase (mo);
  1782. }
  1783.  
  1784. void
  1785. A_OpenShotgun2
  1786. ( player_t*    player,
  1787.   pspdef_t*    psp )
  1788. {
  1789.     S_StartSound (player->mo, sfx_dbopn);
  1790. }
  1791.  
  1792. void
  1793. A_LoadShotgun2
  1794. ( player_t*    player,
  1795.   pspdef_t*    psp )
  1796. {
  1797.     S_StartSound (player->mo, sfx_dbload);
  1798. }
  1799.  
  1800. void
  1801. A_ReFire
  1802. ( player_t*    player,
  1803.   pspdef_t*    psp );
  1804.  
  1805. void
  1806. A_CloseShotgun2
  1807. ( player_t*    player,
  1808.   pspdef_t*    psp )
  1809. {
  1810.     S_StartSound (player->mo, sfx_dbcls);
  1811.     A_ReFire(player,psp);
  1812. }
  1813.  
  1814.  
  1815.  
  1816. mobj_t*        braintargets[32];
  1817. int        numbraintargets;
  1818. int        braintargeton;
  1819.  
  1820. void A_BrainAwake (mobj_t* mo)
  1821. {
  1822.     thinker_t*    thinker;
  1823.     mobj_t*    m;
  1824.     
  1825.     // find all the target spots
  1826.     numbraintargets = 0;
  1827.     braintargeton = 0;
  1828.     
  1829.     thinker = thinkercap.next;
  1830.     for (thinker = thinkercap.next ;
  1831.      thinker != &thinkercap ;
  1832.      thinker = thinker->next)
  1833.     {
  1834.     if (thinker->function.acp1 != (actionf_p1)P_MobjThinker)
  1835.         continue;    // not a mobj
  1836.  
  1837.     m = (mobj_t *)thinker;
  1838.  
  1839.     if (m->type == MT_BOSSTARGET )
  1840.     {
  1841.         braintargets[numbraintargets] = m;
  1842.         numbraintargets++;
  1843.     }
  1844.     }
  1845.     
  1846.     S_StartSound (NULL,sfx_bossit);
  1847. }
  1848.  
  1849.  
  1850. void A_BrainPain (mobj_t*    mo)
  1851. {
  1852.     S_StartSound (NULL,sfx_bospn);
  1853. }
  1854.  
  1855.  
  1856. void A_BrainScream (mobj_t*    mo)
  1857. {
  1858.     int        x;
  1859.     int        y;
  1860.     int        z;
  1861.     mobj_t*    th;
  1862.     
  1863.     for (x=mo->x - 196*FRACUNIT ; x< mo->x + 320*FRACUNIT ; x+= FRACUNIT*8)
  1864.     {
  1865.     y = mo->y - 320*FRACUNIT;
  1866.     z = 128 + P_Random()*2*FRACUNIT;
  1867.     th = P_SpawnMobj (x,y,z, MT_ROCKET);
  1868.     th->momz = P_Random()*512;
  1869.  
  1870.     P_SetMobjState (th, S_BRAINEXPLODE1);
  1871.  
  1872.     th->tics -= P_Random()&7;
  1873.     if (th->tics < 1)
  1874.         th->tics = 1;
  1875.     }
  1876.     
  1877.     S_StartSound (NULL,sfx_bosdth);
  1878. }
  1879.  
  1880.  
  1881.  
  1882. void A_BrainExplode (mobj_t* mo)
  1883. {
  1884.     int        x;
  1885.     int        y;
  1886.     int        z;
  1887.     mobj_t*    th;
  1888.     
  1889.     x = mo->x + (P_Random () - P_Random ())*2048;
  1890.     y = mo->y;
  1891.     z = 128 + P_Random()*2*FRACUNIT;
  1892.     th = P_SpawnMobj (x,y,z, MT_ROCKET);
  1893.     th->momz = P_Random()*512;
  1894.  
  1895.     P_SetMobjState (th, S_BRAINEXPLODE1);
  1896.  
  1897.     th->tics -= P_Random()&7;
  1898.     if (th->tics < 1)
  1899.     th->tics = 1;
  1900. }
  1901.  
  1902.  
  1903. void A_BrainDie (mobj_t*    mo)
  1904. {
  1905.     G_ExitLevel ();
  1906. }
  1907.  
  1908. void A_BrainSpit (mobj_t*    mo)
  1909. {
  1910.     mobj_t*    targ;
  1911.     mobj_t*    newmobj;
  1912.     
  1913.     static int    easy = 0;
  1914.     
  1915.     easy ^= 1;
  1916.     if (gameskill <= sk_easy && (!easy))
  1917.     return;
  1918.         
  1919.     // shoot a cube at current target
  1920.     targ = braintargets[braintargeton];
  1921.     braintargeton = (braintargeton+1)%numbraintargets;
  1922.  
  1923.     // spawn brain missile
  1924.     newmobj = P_SpawnMissile (mo, targ, MT_SPAWNSHOT);
  1925.     newmobj->target = targ;
  1926.     newmobj->reactiontime =
  1927.     ((targ->y - mo->y)/newmobj->momy) / newmobj->state->tics;
  1928.  
  1929.     S_StartSound(NULL, sfx_bospit);
  1930. }
  1931.  
  1932.  
  1933.  
  1934. void A_SpawnFly (mobj_t* mo);
  1935.  
  1936. // travelling cube sound
  1937. void A_SpawnSound (mobj_t* mo)    
  1938. {
  1939.     S_StartSound (mo,sfx_boscub);
  1940.     A_SpawnFly(mo);
  1941. }
  1942.  
  1943. void A_SpawnFly (mobj_t* mo)
  1944. {
  1945.     mobj_t*    newmobj;
  1946.     mobj_t*    fog;
  1947.     mobj_t*    targ;
  1948.     int        r;
  1949.     mobjtype_t    type;
  1950.     
  1951.     if (--mo->reactiontime)
  1952.     return;    // still flying
  1953.     
  1954.     targ = mo->target;
  1955.  
  1956.     // First spawn teleport fog.
  1957.     fog = P_SpawnMobj (targ->x, targ->y, targ->z, MT_SPAWNFIRE);
  1958.     S_StartSound (fog, sfx_telept);
  1959.  
  1960.     // Randomly select monster to spawn.
  1961.     r = P_Random ();
  1962.  
  1963.     // Probability distribution (kind of :),
  1964.     // decreasing likelihood.
  1965.     if ( r<50 )
  1966.     type = MT_TROOP;
  1967.     else if (r<90)
  1968.     type = MT_SERGEANT;
  1969.     else if (r<120)
  1970.     type = MT_SHADOWS;
  1971.     else if (r<130)
  1972.     type = MT_PAIN;
  1973.     else if (r<160)
  1974.     type = MT_HEAD;
  1975.     else if (r<162)
  1976.     type = MT_VILE;
  1977.     else if (r<172)
  1978.     type = MT_UNDEAD;
  1979.     else if (r<192)
  1980.     type = MT_BABY;
  1981.     else if (r<222)
  1982.     type = MT_FATSO;
  1983.     else if (r<246)
  1984.     type = MT_KNIGHT;
  1985.     else
  1986.     type = MT_BRUISER;        
  1987.  
  1988.     newmobj    = P_SpawnMobj (targ->x, targ->y, targ->z, type);
  1989.     if (P_LookForPlayers (newmobj, true) )
  1990.     P_SetMobjState (newmobj, newmobj->info->seestate);
  1991.     
  1992.     // telefrag anything in this spot
  1993.     P_TeleportMove (newmobj, newmobj->x, newmobj->y);
  1994.  
  1995.     // remove self (i.e., cube).
  1996.     P_RemoveMobj (mo);
  1997. }
  1998.  
  1999.  
  2000.  
  2001. void A_PlayerScream (mobj_t* mo)
  2002. {
  2003.     // Default death sound.
  2004.     int        sound = sfx_pldeth;
  2005.     
  2006.     if ( (gamemode == commercial)
  2007.     &&     (mo->health < -50))
  2008.     {
  2009.     // IF THE PLAYER DIES
  2010.     // LESS THAN -50% WITHOUT GIBBING
  2011.     sound = sfx_pdiehi;
  2012.     }
  2013.     
  2014.     S_StartSound (mo, sound);
  2015. }
  2016.