home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / teamsc_1 / client.qc next >
Encoding:
Text File  |  1996-08-07  |  39.5 KB  |  1,671 lines

  1. // prototypes
  2. void() W_WeaponFrame;
  3. void() W_SetCurrentAmmo;
  4. void() player_pain;
  5. void() player_stand1;
  6. void (vector org) spawn_tfog;
  7. void (vector org, entity death_owner) spawn_tdeath;
  8.  
  9. float modelindex_eyes, modelindex_player;
  10.  
  11. /*===========================================================================
  12.  
  13.                              Team Score Compilation
  14.  
  15. ===========================================================================*/
  16.  
  17. // play exit sound and give invunerablity to every one 
  18. void() TeamExit =
  19.    {
  20.    local entity e;
  21.  
  22.    e = find(world, classname, "player");
  23.    while(e)
  24.       {
  25.       sound(e, CHAN_BODY, "player/tornoff2.wav", 1, ATTN_NONE);
  26.       e.items = e.items | IT_INVULNERABILITY;
  27.       e = find(e, classname, "player");
  28.       }
  29.    };
  30.  
  31. // Return a name for the color of a team
  32. string(float Team) GetTeamColor =
  33.    {
  34.    if(Team == 0) return("blue");
  35.    if(Team == 1) return("steel blue");
  36.    if(Team == 2) return("brown");
  37.    if(Team == 3) return("baby blue");
  38.    if(Team == 4) return("green");
  39.    if(Team == 5) return("red");
  40.    if(Team == 6) return("olive");
  41.    if(Team == 7) return("orange");
  42.    if(Team == 8) return("peech");
  43.    if(Team == 9) return("purple");
  44.    if(Team == 10) return("majenta");
  45.    if(Team == 11) return("grey");
  46.    if(Team == 12) return("aqua");
  47.    if(Team == 13) return("yellow");
  48.    };
  49.  
  50. // Get the score for a given team
  51. float(float Team) GetTeamScore =
  52.    {
  53.    local entity e;
  54.    local float TeamFrags;
  55.  
  56. // build a sorted list
  57.    TeamFrags = 32767;
  58.    e = find(world, classname, "player");
  59.    while(e)
  60.       {
  61.       if(e.team == Team)
  62.          {
  63.          if(TeamFrags == 32767) TeamFrags = 0;
  64.          TeamFrags = TeamFrags + e.frags;
  65.          }
  66.       e = find(e, classname, "player");
  67.       }
  68.  
  69.    return(TeamFrags);
  70.    };
  71.  
  72. // Bulitin print team scores before intermision
  73. void() PrintTeamScores =
  74.    {
  75.    local float Team, WinFrags, TeamFrags, Winners;
  76.  
  77. // get highest frag count
  78.    Team = 0;
  79.    WinFrags = -100;
  80.    while(Team < 14)
  81.       {
  82.       TeamFrags = GetTeamScore(Team);
  83.       if(TeamFrags != 32767)
  84.          {
  85.          if(TeamFrags > WinFrags) WinFrags = TeamFrags;
  86.  
  87. // print scores
  88.          bprint("Team ");
  89.          bprint(GetTeamColor(Team));
  90.          bprint(" got ");
  91.          bprint(ftos(TeamFrags));
  92.          bprint(" frags.\n");
  93.          }
  94.       Team = Team + 1;
  95.       }
  96.  
  97. // get number of team with most frags
  98.    Team = 0;
  99.    Winners = 0;
  100.    while(Team < 14)
  101.       {
  102.       TeamFrags = GetTeamScore(Team);
  103.       if(TeamFrags != 32767)
  104.          {
  105.          if(TeamFrags == WinFrags) Winners = Winners + 1;
  106.          }
  107.       Team = Team + 1;
  108.       }
  109.  
  110. // list winners
  111.    Team = 0;
  112.    while(Team < 14)
  113.       {
  114.       TeamFrags = GetTeamScore(Team);
  115.       if(TeamFrags != 32767)
  116.          {
  117.          if(TeamFrags == WinFrags)
  118.             {
  119.             if(Winners == 1)
  120.                {
  121.                bprint("Team ");
  122.                bprint(GetTeamColor(Team));
  123.                bprint(" won with ");
  124.                bprint(ftos(TeamFrags));
  125.                bprint(" frags.\n");
  126.                }
  127.             else
  128.                {
  129.                bprint("Team ");
  130.                bprint(GetTeamColor(Team));
  131.                bprint(" tied for first with ");
  132.                bprint(ftos(TeamFrags));
  133.                bprint(" frags.\n");
  134.                }
  135.             }
  136.          }
  137.       Team = Team + 1;
  138.       }
  139.    };
  140.  
  141. /*
  142. =============================================================================
  143.  
  144.                 LEVEL CHANGING / INTERMISSION
  145.  
  146. =============================================================================
  147. */
  148.  
  149. float    intermission_running;
  150. float    intermission_exittime;
  151.  
  152. /*QUAKED info_intermission (1 0.5 0.5) (-16 -16 -16) (16 16 16)
  153. This is the camera point for the intermission.
  154. Use mangle instead of angle, so you can set pitch or roll as well as yaw.  'pitch roll yaw'
  155. */
  156. void() info_intermission =
  157. {
  158. };
  159.  
  160. void() SetChangeParms =
  161. {
  162. // remove items
  163.     self.items = self.items - (self.items & 
  164.     (IT_KEY1 | IT_KEY2 | IT_INVISIBILITY | IT_INVULNERABILITY | IT_SUIT | IT_QUAD) );
  165.     
  166. // cap super health
  167.     if (self.health > 100)
  168.         self.health = 100;
  169.     if (self.health < 50)
  170.         self.health = 50;
  171.     parm1 = self.items;
  172.     parm2 = self.health;
  173.     parm3 = self.armorvalue;
  174.     if (self.ammo_shells < 25)
  175.         parm4 = 25;
  176.     else
  177.         parm4 = self.ammo_shells;
  178.     parm5 = self.ammo_nails;
  179.     parm6 = self.ammo_rockets;
  180.     parm7 = self.ammo_cells;
  181.     parm8 = self.weapon;
  182.     parm9 = self.armortype * 100;
  183. };
  184.  
  185. void() SetNewParms =
  186.    {
  187.    parm1 = IT_SHOTGUN | IT_AXE;
  188.    parm2 = 100;
  189.    parm3 = 0;
  190.    parm4 = 25;
  191.    parm5 = 0;
  192.    parm6 = 0;
  193.    parm6 = 0;
  194.    parm8 = 1;
  195.    parm9 = 0;
  196.    };
  197.  
  198. void() DecodeLevelParms =
  199. {
  200.     if (serverflags)
  201.     {
  202.         if (world.model == "maps/start.bsp")
  203.             SetNewParms ();        // take away all stuff on starting new episode
  204.     }
  205.     
  206.     self.items = parm1;
  207.     self.health = parm2;
  208.     self.armorvalue = parm3;
  209.     self.ammo_shells = parm4;
  210.     self.ammo_nails = parm5;
  211.     self.ammo_rockets = parm6;
  212.     self.ammo_cells = parm7;
  213.     self.weapon = parm8;
  214.     self.armortype = parm9 * 0.01;
  215. };
  216.  
  217. /*
  218. ============
  219. FindIntermission
  220.  
  221. Returns the entity to view from
  222. ============
  223. */
  224. entity() FindIntermission =
  225. {
  226.     local    entity spot;
  227.     local    float cyc;
  228.  
  229. // look for info_intermission first
  230.     spot = find (world, classname, "info_intermission");
  231.     if (spot)
  232.     {    // pick a random one
  233.         cyc = random() * 4;
  234.         while (cyc > 1)
  235.         {
  236.             spot = find (spot, classname, "info_intermission");
  237.             if (!spot)
  238.                 spot = find (spot, classname, "info_intermission");
  239.             cyc = cyc - 1;
  240.         }
  241.         return spot;
  242.     }
  243.  
  244. // then look for the start position
  245.     spot = find (world, classname, "info_player_start");
  246.     if (spot)
  247.         return spot;
  248.     
  249. // testinfo_player_start is only found in regioned levels
  250.     spot = find (world, classname, "testplayerstart");
  251.     if (spot)
  252.         return spot;
  253.     
  254.     objerror ("FindIntermission: no spot");
  255. };
  256.  
  257.  
  258. string nextmap;
  259. void() GotoNextMap =
  260.    {
  261. // if samelevel is set, stay on same level
  262.    if(cvar("samelevel")) changelevel(mapname);
  263.    else changelevel(nextmap);
  264.    };
  265.  
  266.  
  267. void() ExitIntermission =
  268.    {
  269. // skip any text in deathmatch
  270.    if(deathmatch)
  271.       {
  272.       GotoNextMap();
  273.       return;
  274.       }
  275.     
  276.    intermission_exittime = time + 1;
  277.    intermission_running = intermission_running + 1;
  278.  
  279. //
  280. // run some text if at the end of an episode
  281. //
  282.    if(intermission_running == 2)
  283.       {
  284.       if(world.model == "maps/e1m7.bsp")
  285.          {
  286.          WriteByte (MSG_ALL, SVC_CDTRACK);
  287.          WriteByte (MSG_ALL, 2);
  288.          WriteByte (MSG_ALL, 3);
  289.          if(!cvar("registered"))
  290.             {
  291.             WriteByte(MSG_ALL, SVC_FINALE);
  292.             WriteString(MSG_ALL, "As the corpse of the monstrous entity\nChthon sinks back into the lava whence\nit rose, you grip the Rune of Earth\nMagic tightly. Now that you have\nconquered the Dimension of the Doomed,\nrealm of Earth Magic, you are ready to\ncomplete your task in the other three\nhaunted lands of Quake. Or are you? If\nyou don't register Quake, you'll never\nknow what awaits you in the Realm of\nBlack Magic, the Netherworld, and the\nElder World!");
  293.             }
  294.          else
  295.             {
  296.             WriteByte(MSG_ALL, SVC_FINALE);
  297.             WriteString(MSG_ALL, "As the corpse of the monstrous entity\nChthon sinks back into the lava whence\nit rose, you grip the Rune of Earth\nMagic tightly. Now that you have\nconquered the Dimension of the Doomed,\nrealm of Earth Magic, you are ready to\ncomplete your task. A Rune of magic\npower lies at the end of each haunted\nland of Quake. Go forth, seek the\ntotality of the four Runes!");
  298.             }
  299.          return;
  300.          }
  301.       else if(world.model == "maps/e2m6.bsp")
  302.          {
  303.          WriteByte(MSG_ALL, SVC_CDTRACK);
  304.          WriteByte(MSG_ALL, 2);
  305.          WriteByte(MSG_ALL, 3);
  306.  
  307.          WriteByte(MSG_ALL, SVC_FINALE);
  308.          WriteString(MSG_ALL, "The Rune of Black Magic throbs evilly in\nyour hand and whispers dark thoughts\ninto your brain. You learn the inmost\nlore of the Hell-Mother; Shub-Niggurath!\nYou now know that she is behind all the\nterrible plotting which has led to so\nmuch death and horror. But she is not\ninviolate! Armed with this Rune, you\nrealize that once all four Runes are\ncombined, the gate to Shub-Niggurath's\nPit will open, and you can face the\nWitch-Goddess herself in her frightful\notherworld cathedral.");
  309.          return;
  310.          }
  311.       else if(world.model == "maps/e3m6.bsp")
  312.          {
  313.          WriteByte(MSG_ALL, SVC_CDTRACK);
  314.          WriteByte(MSG_ALL, 2);
  315.          WriteByte(MSG_ALL, 3);
  316.  
  317.          WriteByte(MSG_ALL, SVC_FINALE);
  318.          WriteString(MSG_ALL, "The charred viscera of diabolic horrors\nbubble viscously as you seize the Rune\nof Hell Magic. Its heat scorches your\nhand, and its terrible secrets blight\nyour mind. Gathering the shreds of your\ncourage, you shake the devil's shackles\nfrom your soul, and become ever more\nhard and determined to destroy the\nhideous creatures whose mere existence\nthreatens the souls and psyches of all\nthe population of Earth.");
  319.          return;
  320.          }
  321.       else if(world.model == "maps/e4m7.bsp")
  322.          {
  323.          WriteByte (MSG_ALL, SVC_CDTRACK);
  324.          WriteByte (MSG_ALL, 2);
  325.          WriteByte (MSG_ALL, 3);
  326.  
  327.          WriteByte (MSG_ALL, SVC_FINALE);
  328.          WriteString (MSG_ALL, "Despite the awful might of the Elder\nWorld, you have achieved the Rune of\nElder Magic, capstone of all types of\narcane wisdom. Beyond good and evil,\nbeyond life and death, the Rune\npulsates, heavy with import. Patient and\npotent, the Elder Being Shub-Niggurath\nweaves her dire plans to clear off all\nlife from the Earth, and bring her own\nfoul offspring to our world! For all the\ndwellers in these nightmare dimensions\nare her descendants! Once all Runes of\nmagic power are united, the energy\nbehind them will blast open the Gateway\nto Shub-Niggurath, and you can travel\nthere to foil the Hell-Mother's plots\nin person.");
  329.          return;
  330.          }
  331.  
  332.       GotoNextMap();
  333.       }
  334.     
  335.    if(intermission_running == 3)
  336.       {
  337. // shareware episode has been completed, go to sell screen
  338.       if(!cvar("registered"))
  339.          {       
  340.          WriteByte(MSG_ALL, SVC_SELLSCREEN);
  341.          return;
  342.          }
  343.         
  344.       if((serverflags & 15) == 15)
  345.          {
  346.          WriteByte(MSG_ALL, SVC_FINALE);
  347.          WriteString(MSG_ALL, "Now, you have all four Runes. You sense\ntremendous invisible forces moving to\nunseal ancient barriers. Shub-Niggurath\nhad hoped to use the Runes Herself to\nclear off the Earth, but now instead,\nyou will use them to enter her home and\nconfront her as an avatar of avenging\nEarth-life. If you defeat her, you will\nbe remembered forever as the savior of\nthe planet. If she conquers, it will be\nas if you had never been born.");
  348.          return;
  349.          }
  350.       }
  351.    GotoNextMap();
  352.    };
  353.  
  354. /*
  355. ============
  356. IntermissionThink
  357.  
  358. When the player presses attack or jump, change to the next level
  359. ============
  360. */
  361. void() IntermissionThink =
  362.    {
  363.    if(time < intermission_exittime) return;
  364.  
  365.    if(!self.button0 && !self.button1 && !self.button2) return;
  366.     
  367.    ExitIntermission();
  368.    };
  369.  
  370. void() execute_changelevel =
  371.    {
  372.    local entity pos;
  373.  
  374.    intermission_running = 1;
  375.     
  376. // enforce a wait time before allowing changelevel
  377.    if(deathmatch) intermission_exittime = time + 5;
  378.    else intermission_exittime = time + 2;
  379.  
  380.    WriteByte (MSG_ALL, SVC_CDTRACK);
  381.    WriteByte (MSG_ALL, 3);
  382.    WriteByte (MSG_ALL, 3);
  383.     
  384.    pos = FindIntermission();
  385.  
  386.    other = find(world, classname, "player");
  387.    while(other != world)
  388.       {
  389.       other.view_ofs = '0 0 0';
  390.       other.angles = other.v_angle = pos.mangle;
  391.       other.fixangle = TRUE;          // turn this way immediately
  392.       other.nextthink = time + 0.5;
  393.       other.takedamage = DAMAGE_NO;
  394.       other.solid = SOLID_NOT;
  395.       other.movetype = MOVETYPE_NONE;
  396.       other.modelindex = 0;
  397.       setorigin(other, pos.origin);
  398.       other = find(other, classname, "player");
  399.       } 
  400.  
  401.    WriteByte(MSG_ALL, SVC_INTERMISSION);
  402.    };
  403.  
  404.  
  405. void() changelevel_touch =
  406.    {
  407.    local entity pos;
  408.  
  409.    if(other.classname != "player") return;
  410.  
  411.    if(cvar("noexit"))
  412.       {
  413.       T_Damage(other, self, self, 50000);
  414.       return;
  415.       }
  416.    bprint(other.netname);
  417.    bprint(" exited the level\n");
  418.     
  419.    nextmap = self.map;
  420.  
  421.    SUB_UseTargets();
  422.  
  423. // NO_INTERMISSION
  424.    if((self.spawnflags & 1) && (deathmatch == 0))
  425.       {       
  426.       GotoNextMap();
  427.       return;
  428.       }
  429.     
  430.    self.touch = SUB_Null;
  431.  
  432. // change level in 5 sec
  433.    if(cvar("teamplay"))
  434.       {
  435. // print scores
  436.       PrintTeamScores();
  437.       TeamExit();
  438. // change level in after delay
  439.       self.think = execute_changelevel;
  440.       self.nextthink = time + EXITWAIT;
  441.       }
  442.    else
  443.       {
  444.       self.think = execute_changelevel;
  445.       self.nextthink = time + 0.1;
  446.       }
  447.    };
  448.  
  449. /*
  450. QUAKED trigger_changelevel (0.5 0.5 0.5) ? NO_INTERMISSION
  451. When the player touches this, he gets sent to the map listed in the "map" variable.  Unless the NO_INTERMISSION flag is set, the view will go to the info_intermission spot and display stats.
  452. */
  453. void() trigger_changelevel =
  454.    {
  455.    if(!self.map) objerror("chagnelevel trigger doesn't have map");
  456.     
  457.    InitTrigger();
  458.    self.touch = changelevel_touch;
  459.    };
  460.  
  461.  
  462. /*
  463. =============================================================================
  464.  
  465.                 PLAYER GAME EDGE FUNCTIONS
  466.  
  467. =============================================================================
  468. */
  469.  
  470. void() set_suicide_frame;
  471.  
  472. // called by ClientKill and DeadThink
  473. void() respawn =
  474.    {
  475.    if(coop)
  476.       {
  477. // make a copy of the dead body for appearances sake
  478.       CopyToBodyQue (self);
  479. // get the spawn parms as they were at level start
  480.       setspawnparms (self);
  481. // respawn       
  482.       PutClientInServer();
  483.       }
  484.    else if(deathmatch)
  485.       {
  486. // make a copy of the dead body for appearances sake
  487.       CopyToBodyQue(self);
  488. // set default spawn parms
  489.       SetNewParms();
  490. // respawn       
  491.       PutClientInServer ();
  492.       }
  493.    else
  494.       {
  495. // restart the entire server
  496.       localcmd("restart\n");
  497.       }
  498.    };
  499.  
  500.  
  501. /*
  502. ============
  503. ClientKill
  504.  
  505. Player entered the suicide command
  506. ============
  507. */
  508. void() ClientKill =
  509.    {
  510.    bprint(self.netname);
  511.    bprint (" suicides\n");
  512.    set_suicide_frame();
  513.    self.modelindex = modelindex_player;
  514.    self.frags = self.frags - 2;    // extra penalty
  515.    respawn();
  516.    };
  517.  
  518. float(vector v) CheckSpawnPoint =
  519.    {
  520.    return FALSE;
  521.    };
  522.  
  523. /*
  524. ============
  525. SelectSpawnPoint
  526.  
  527. Returns the entity to spawn at
  528. ============
  529. */
  530. entity() SelectSpawnPoint =
  531. {
  532.     local    entity spot;
  533.     
  534. // testinfo_player_start is only found in regioned levels
  535.     spot = find (world, classname, "testplayerstart");
  536.     if (spot)
  537.         return spot;
  538.         
  539. // choose a info_player_deathmatch point
  540.     if (coop)
  541.     {
  542.         lastspawn = find(lastspawn, classname, "info_player_coop");
  543.         if (lastspawn == world)
  544.             lastspawn = find (lastspawn, classname, "info_player_start");
  545.         if (lastspawn != world)
  546.             return lastspawn;
  547.     }
  548.     else if (deathmatch)
  549.     {
  550.         lastspawn = find(lastspawn, classname, "info_player_deathmatch");
  551.         if (lastspawn == world)
  552.             lastspawn = find (lastspawn, classname, "info_player_deathmatch");
  553.         if (lastspawn != world)
  554.             return lastspawn;
  555.     }
  556.  
  557.     if (serverflags)
  558.     {    // return with a rune to start
  559.         spot = find (world, classname, "info_player_start2");
  560.         if (spot)
  561.             return spot;
  562.     }
  563.     
  564.     spot = find (world, classname, "info_player_start");
  565.     if (!spot)
  566.         error ("PutClientInServer: no info_player_start on level");
  567.     
  568.     return spot;
  569. };
  570.  
  571. /*
  572. ===========
  573. PutClientInServer
  574.  
  575. called each time a player is spawned
  576. ============
  577. */
  578. void() DecodeLevelParms;
  579. void() PlayerDie;
  580.  
  581.  
  582. void() PutClientInServer =
  583. {
  584.     local    entity spot;
  585.  
  586.     self.classname = "player";
  587.     self.health = 100;
  588.     self.takedamage = DAMAGE_AIM;
  589.     self.solid = SOLID_SLIDEBOX;
  590.     self.movetype = MOVETYPE_WALK;
  591.     self.show_hostile = 0;
  592.     self.max_health = 100;
  593.     self.flags = FL_CLIENT;
  594.     self.air_finished = time + 12;
  595.     self.dmg = 2;           // initial water damage
  596.     self.super_damage_finished = 0;
  597.     self.radsuit_finished = 0;
  598.     self.invisible_finished = 0;
  599.     self.invincible_finished = 0;
  600.     self.effects = 0;
  601.     self.invincible_time = 0;
  602.  
  603.     DecodeLevelParms ();
  604.     
  605.     W_SetCurrentAmmo ();
  606.  
  607.     self.attack_finished = time;
  608.     self.th_pain = player_pain;
  609.     self.th_die = PlayerDie;
  610.     
  611.     self.deadflag = DEAD_NO;
  612. // paustime is set by teleporters to keep the player from moving a while
  613.     self.pausetime = 0;
  614.     
  615.     spot = SelectSpawnPoint ();
  616.  
  617.     self.origin = spot.origin + '0 0 1';
  618.     self.angles = spot.angles;
  619.     self.fixangle = TRUE;        // turn this way immediately
  620.  
  621. // oh, this is a hack!
  622.     setmodel (self, "progs/eyes.mdl");
  623.     modelindex_eyes = self.modelindex;
  624.  
  625.     setmodel (self, "progs/player.mdl");
  626.     modelindex_player = self.modelindex;
  627.  
  628.     setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
  629.     
  630.     self.view_ofs = '0 0 22';
  631.  
  632.     player_stand1 ();
  633.     
  634.     if (deathmatch || coop)
  635.     {
  636.         makevectors(self.angles);
  637.         spawn_tfog (self.origin + v_forward*20);
  638.     }
  639.  
  640.     spawn_tdeath (self.origin, self);
  641. };
  642.  
  643.  
  644. /*
  645. =============================================================================
  646.  
  647.                 QUAKED FUNCTIONS
  648.  
  649. =============================================================================
  650. */
  651.  
  652.  
  653. /*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 24)
  654. The normal starting point for a level.
  655. */
  656. void() info_player_start =
  657. {
  658. };
  659.  
  660.  
  661. /*QUAKED info_player_start2 (1 0 0) (-16 -16 -24) (16 16 24)
  662. Only used on start map for the return point from an episode.
  663. */
  664. void() info_player_start2 =
  665. {
  666. };
  667.  
  668.  
  669. /*
  670. saved out by quaked in region mode
  671. */
  672. void() testplayerstart =
  673. {
  674. };
  675.  
  676. /*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 24)
  677. potential spawning position for deathmatch games
  678. */
  679. void() info_player_deathmatch =
  680. {
  681. };
  682.  
  683. /*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 24)
  684. potential spawning position for coop games
  685. */
  686. void() info_player_coop =
  687. {
  688. };
  689.  
  690. /*
  691. ===============================================================================
  692.  
  693. RULES
  694.  
  695. ===============================================================================
  696. */
  697.  
  698. void(entity c) PrintClientScore =
  699. {
  700.     if (c.frags > -10 && c.frags < 0)
  701.         bprint (" ");
  702.     else if (c.frags >= 0)
  703.     {
  704.         if (c.frags < 100)
  705.             bprint (" ");
  706.         if (c.frags < 10)
  707.             bprint (" ");
  708.     }
  709.     bprint (ftos(c.frags));
  710.     bprint (" ");
  711.     bprint (c.netname);
  712.     bprint ("\n");
  713. };
  714.  
  715. void() DumpScore =
  716. {
  717.     local entity    e, sort, walk;
  718.  
  719.     if (world.chain)
  720.         error ("DumpScore: world.chain is set");
  721.  
  722. // build a sorted lis
  723.     e = find(world, classname, "player");
  724.     sort = world;
  725.     while (e)
  726.     {
  727.         if (!sort)
  728.         {
  729.             sort = e;
  730.             e.chain = world;
  731.         }
  732.         else
  733.         {
  734.             if (e.frags > sort.frags)
  735.             {
  736.                 e.chain = sort;
  737.                 sort = e;
  738.             }
  739.             else
  740.             {
  741.                 walk = sort;
  742.                 do
  743.                 {
  744.                     if (!walk.chain)
  745.                     {
  746.                         e.chain = world;
  747.                         walk.chain = e;
  748.                     }
  749.                     else if (walk.chain.frags < e.frags)
  750.                     {
  751.                         e.chain = walk.chain;
  752.                         walk.chain = e;
  753.                     }
  754.                     else
  755.                         walk = walk.chain;
  756.                 } while (walk.chain != e);
  757.             }
  758.         }
  759.  
  760.         e = find(e, classname, "player");
  761.     }
  762.  
  763. // print the list
  764.  
  765.     bprint ("\n");
  766.     while (sort)
  767.     {
  768.                 PrintClientScore(sort);
  769.         sort = sort.chain;
  770.     }
  771.     bprint ("\n");
  772. };
  773.  
  774. /*--------------------------------------+
  775. |  go to the next level for deathmatch  |
  776. +--------------------------------------*/
  777. void() NextLevel =
  778.    {
  779.    local entity o, e;
  780.  
  781. // find a trigger changelevel
  782.    o = find(world, classname, "trigger_changelevel");
  783.    if(!o || mapname == "start")
  784.       {
  785. // go back to same map if no trigger_changelevel
  786.       o = spawn();
  787.       o.map = mapname;
  788.       }
  789.  
  790.    nextmap = o.map;
  791.  
  792.    if(o.nextthink < time)
  793.       {
  794. // print team scores
  795.       if(cvar("teamplay") != 0)
  796.          {
  797. // print scores
  798.          PrintTeamScores();
  799.          TeamExit();
  800. // change level in 5 sec
  801.          o.think = execute_changelevel;
  802.          o.nextthink = time + EXITWAIT;
  803.          }
  804.       else
  805.          {
  806.          o.think = execute_changelevel;
  807.          o.nextthink = time + 0.1;
  808.          }
  809.       }
  810.    };
  811.  
  812. /*
  813. ============
  814. CheckRules
  815.  
  816. Exit deathmatch games upon conditions
  817. ============
  818. */
  819. void() CheckRules =
  820.    {
  821.    local float timelimit;
  822.    local float fraglimit;
  823.     
  824. // someone else quit the game already
  825.    if(gameover) return;
  826.         
  827.    timelimit = cvar("timelimit") * 60;
  828.    fraglimit = cvar("fraglimit");
  829.     
  830.    if(timelimit && time >= timelimit)
  831.       {
  832.       NextLevel();
  833. /*
  834.       gameover = TRUE;
  835.       bprint("\n\n\n==============================\n");
  836.       bprint("game exited after ");
  837.       bprint(ftos(timelimit/60));
  838.       bprint(" minutes\n");
  839.       DumpScore();
  840.       localcmd("killserver\n");
  841. */
  842.       return;
  843.       }
  844.     
  845.    if(fraglimit && self.frags >= fraglimit)
  846.       {
  847.       NextLevel();
  848. /*
  849.       gameover = TRUE;
  850.       bprint("\n\n\n==============================\n");
  851.       bprint("game exited after ");
  852.       bprint(ftos(self.frags));
  853.       bprint(" frags\n");
  854.       DumpScore();
  855.       localcmd("killserver\n");
  856. */
  857.       return;
  858.       }
  859.    };
  860.  
  861. //============================================================================
  862.  
  863. void() PlayerDeathThink =
  864.    {
  865.    local entity old_self;
  866.    local float forward;
  867.  
  868.    if((self.flags & FL_ONGROUND))
  869.       {
  870.       forward = vlen(self.velocity);
  871.       forward = forward - 20;
  872.       if(forward <= 0) self.velocity = '0 0 0';
  873.       else self.velocity = forward * normalize(self.velocity);
  874.       }
  875.  
  876. // wait for all buttons released
  877.    if(self.deadflag == DEAD_DEAD)
  878.       {
  879.       if(self.button2 || self.button1 || self.button0) return;
  880.       self.deadflag = DEAD_RESPAWNABLE;
  881.       return;
  882.       }
  883.  
  884. // wait for any button down
  885.    if(!self.button2 && !self.button1 && !self.button0 && time < self.teleport_time) return;
  886.  
  887.    self.button0 = 0;
  888.    self.button1 = 0;
  889.    self.button2 = 0;
  890.    respawn();
  891.    };
  892.  
  893.  
  894. void() PlayerJump =
  895. {
  896.     local vector start, end;
  897.     
  898.     if (self.flags & FL_WATERJUMP)
  899.         return;
  900.     
  901.     if (self.waterlevel >= 2)
  902.     {
  903.         if (self.watertype == CONTENT_WATER)
  904.             self.velocity_z = 100;
  905.         else if (self.watertype == CONTENT_SLIME)
  906.             self.velocity_z = 80;
  907.         else
  908.             self.velocity_z = 50;
  909.  
  910. // play swiming sound
  911.         if (self.swim_flag < time)
  912.         {
  913.             self.swim_flag = time + 1;
  914.             if (random() < 0.5)
  915.                 sound (self, CHAN_BODY, "misc/water1.wav", 1, ATTN_NORM);
  916.             else
  917.                 sound (self, CHAN_BODY, "misc/water2.wav", 1, ATTN_NORM);
  918.         }
  919.  
  920.         return;
  921.     }
  922.  
  923.     if (!(self.flags & FL_ONGROUND))
  924.         return;
  925.  
  926.     if ( !(self.flags & FL_JUMPRELEASED) )
  927.         return;        // don't pogo stick
  928.  
  929.     self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
  930.  
  931.     self.flags = self.flags - FL_ONGROUND;    // don't stairwalk
  932.     
  933.     self.button2 = 0;
  934. // player jumping sound
  935.     sound (self, CHAN_BODY, "player/plyrjmp8.wav", 1, ATTN_NORM);
  936.     self.velocity_z = self.velocity_z + 270;
  937. };
  938.  
  939.  
  940. /*
  941. ===========
  942. WaterMove
  943.  
  944. ============
  945. */
  946. .float    dmgtime;
  947.  
  948. void() WaterMove =
  949. {
  950. //dprint (ftos(self.waterlevel));
  951.     if (self.movetype == MOVETYPE_NOCLIP)
  952.         return;
  953.     if (self.health < 0)
  954.         return;
  955.  
  956.     if (self.waterlevel != 3)
  957.     {
  958.         if (self.air_finished < time)
  959.             sound (self, CHAN_VOICE, "player/gasp2.wav", 1, ATTN_NORM);
  960.         else if (self.air_finished < time + 9)
  961.             sound (self, CHAN_VOICE, "player/gasp1.wav", 1, ATTN_NORM);
  962.         self.air_finished = time + 12;
  963.         self.dmg = 2;
  964.     }
  965.     else if (self.air_finished < time)
  966.     {    // drown!
  967.         if (self.pain_finished < time)
  968.         {
  969.             self.dmg = self.dmg + 2;
  970.             if (self.dmg > 15)
  971.                 self.dmg = 10;
  972.             T_Damage (self, world, world, self.dmg);
  973.             self.pain_finished = time + 1;
  974.         }
  975.     }
  976.     
  977.     if (!self.waterlevel)
  978.     {
  979.         if (self.flags & FL_INWATER)
  980.         {    
  981.             // play leave water sound
  982.             sound (self, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM);
  983.             self.flags = self.flags - FL_INWATER;
  984.         }
  985.         return;
  986.     }
  987.  
  988.     if (self.watertype == CONTENT_LAVA)
  989.     {    // do damage
  990.         if (self.dmgtime < time)
  991.         {
  992.             if (self.radsuit_finished > time)
  993.                 self.dmgtime = time + 1;
  994.             else
  995.                 self.dmgtime = time + 0.2;
  996.  
  997.             T_Damage (self, world, world, 10*self.waterlevel);
  998.         }
  999.     }
  1000.     else if (self.watertype == CONTENT_SLIME)
  1001.     {    // do damage
  1002.         if (self.dmgtime < time && self.radsuit_finished < time)
  1003.         {
  1004.             self.dmgtime = time + 1;
  1005.             T_Damage (self, world, world, 4*self.waterlevel);
  1006.         }
  1007.     }
  1008.     
  1009.     if ( !(self.flags & FL_INWATER) )
  1010.     {    
  1011.  
  1012. // player enter water sound
  1013.  
  1014.         if (self.watertype == CONTENT_LAVA)
  1015.             sound (self, CHAN_BODY, "player/inlava.wav", 1, ATTN_NORM);
  1016.         if (self.watertype == CONTENT_WATER)
  1017.             sound (self, CHAN_BODY, "player/inh2o.wav", 1, ATTN_NORM);
  1018.         if (self.watertype == CONTENT_SLIME)
  1019.             sound (self, CHAN_BODY, "player/slimbrn2.wav", 1, ATTN_NORM);
  1020.  
  1021.         self.flags = self.flags + FL_INWATER;
  1022.         self.dmgtime = 0;
  1023.     }
  1024.     
  1025.     if (! (self.flags & FL_WATERJUMP) )
  1026.         self.velocity = self.velocity - 0.8*self.waterlevel*frametime*self.velocity;
  1027. };
  1028.  
  1029. void() CheckWaterJump =
  1030. {
  1031.     local vector start, end;
  1032.  
  1033. // check for a jump-out-of-water
  1034.     makevectors (self.angles);
  1035.     start = self.origin;
  1036.     start_z = start_z + 8; 
  1037.     v_forward_z = 0;
  1038.     normalize(v_forward);
  1039.     end = start + v_forward*24;
  1040.     traceline (start, end, TRUE, self);
  1041.     if (trace_fraction < 1)
  1042.     {    // solid at waist
  1043.         start_z = start_z + self.maxs_z - 8;
  1044.         end = start + v_forward*24;
  1045.         self.movedir = trace_plane_normal * -50;
  1046.         traceline (start, end, TRUE, self);
  1047.         if (trace_fraction == 1)
  1048.         {    // open at eye level
  1049.             self.flags = self.flags | FL_WATERJUMP;
  1050.             self.velocity_z = 225;
  1051.             self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
  1052.             self.teleport_time = time + 2;    // safety net
  1053.             return;
  1054.         }
  1055.     }
  1056. };
  1057.  
  1058.  
  1059. /*
  1060. ================
  1061. PlayerPreThink
  1062.  
  1063. Called every frame before physics are run
  1064. ================
  1065. */
  1066. void() PlayerPreThink =
  1067.    {
  1068.    local float mspeed, aspeed;
  1069.    local float r;
  1070.  
  1071.    if(intermission_running)
  1072.       {
  1073.       IntermissionThink ();   // otherwise a button could be missed between
  1074.       return;                                 // the think tics
  1075.       }
  1076.  
  1077.    if(self.view_ofs == '0 0 0') return;  // intermission or finale
  1078.  
  1079.    makevectors(self.v_angle);             // is this still used
  1080.  
  1081.    CheckRules();
  1082.    WaterMove();
  1083.  
  1084.    if(self.waterlevel == 2) CheckWaterJump ();
  1085.  
  1086.    if(self.deadflag >= DEAD_DEAD)
  1087.       {
  1088.       PlayerDeathThink();
  1089.       return;
  1090.       }
  1091.     
  1092.    if(self.deadflag == DEAD_DYING) return; // dying, so do nothing
  1093.  
  1094.    if(self.button2)
  1095.       {
  1096.       PlayerJump();
  1097.       }
  1098.    else self.flags = self.flags | FL_JUMPRELEASED;
  1099.  
  1100. // teleporters can force a non-moving pause time    
  1101.    if(time < self.pausetime) self.velocity = '0 0 0';
  1102.    };
  1103.     
  1104. /*
  1105. ================
  1106. CheckPowerups
  1107.  
  1108. Check for turning off powerups
  1109. ================
  1110. */
  1111. void() CheckPowerups =
  1112. {
  1113.     if (self.health <= 0)
  1114.         return;
  1115.  
  1116. // invisibility
  1117.     if (self.invisible_finished)
  1118.     {
  1119. // sound and screen flash when items starts to run out
  1120.         if (self.invisible_sound < time)
  1121.         {
  1122.             sound (self, CHAN_AUTO, "items/inv3.wav", 0.5, ATTN_IDLE);
  1123.             self.invisible_sound = time + ((random() * 3) + 1);
  1124.         }
  1125.  
  1126.  
  1127.         if (self.invisible_finished < time + 3)
  1128.         {
  1129.             if (self.invisible_time == 1)
  1130.             {
  1131.                 sprint (self, "Ring of Shadows magic is fading\n");
  1132.                 stuffcmd (self, "bf\n");
  1133.                 sound (self, CHAN_AUTO, "items/inv2.wav", 1, ATTN_NORM);
  1134.                 self.invisible_time = time + 1;
  1135.             }
  1136.             
  1137.             if (self.invisible_time < time)
  1138.             {
  1139.                 self.invisible_time = time + 1;
  1140.                 stuffcmd (self, "bf\n");
  1141.             }
  1142.         }
  1143.  
  1144.         if (self.invisible_finished < time)
  1145.         {    // just stopped
  1146.             self.items = self.items - IT_INVISIBILITY;
  1147.             self.invisible_finished = 0;
  1148.             self.invisible_time = 0;
  1149.         }
  1150.         
  1151.     // use the eyes
  1152.         self.frame = 0;
  1153.         self.modelindex = modelindex_eyes;
  1154.     }
  1155.     else
  1156.         self.modelindex = modelindex_player;    // don't use eyes
  1157.  
  1158. // invincibility
  1159.     if (self.invincible_finished)
  1160.     {
  1161. // sound and screen flash when items starts to run out
  1162.         if (self.invincible_finished < time + 3)
  1163.         {
  1164.             if (self.invincible_time == 1)
  1165.             {
  1166.                 sprint (self, "Protection is almost burned out\n");
  1167.                 stuffcmd (self, "bf\n");
  1168.                 sound (self, CHAN_AUTO, "items/protect2.wav", 1, ATTN_NORM);
  1169.                 self.invincible_time = time + 1;
  1170.             }
  1171.             
  1172.             if (self.invincible_time < time)
  1173.             {
  1174.                 self.invincible_time = time + 1;
  1175.                 stuffcmd (self, "bf\n");
  1176.             }
  1177.         }
  1178.         
  1179.         if (self.invincible_finished < time)
  1180.         {    // just stopped
  1181.             self.items = self.items - IT_INVULNERABILITY;
  1182.             self.invincible_time = 0;
  1183.             self.invincible_finished = 0;
  1184.         }
  1185.         if (self.invincible_finished > time)
  1186.             self.effects = self.effects | EF_DIMLIGHT;
  1187.         else
  1188.             self.effects = self.effects - (self.effects & EF_DIMLIGHT);
  1189.     }
  1190.  
  1191. // super damage
  1192.     if (self.super_damage_finished)
  1193.     {
  1194.  
  1195. // sound and screen flash when items starts to run out
  1196.  
  1197.         if (self.super_damage_finished < time + 3)
  1198.         {
  1199.             if (self.super_time == 1)
  1200.             {
  1201.                 sprint (self, "Quad Damage is wearing off\n");
  1202.                 stuffcmd (self, "bf\n");
  1203.                 sound (self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM);
  1204.                 self.super_time = time + 1;
  1205.             }      
  1206.             
  1207.             if (self.super_time < time)
  1208.             {
  1209.                 self.super_time = time + 1;
  1210.                 stuffcmd (self, "bf\n");
  1211.             }
  1212.         }
  1213.  
  1214.         if (self.super_damage_finished < time)
  1215.         {    // just stopped
  1216.             self.items = self.items - IT_QUAD;
  1217.             self.super_damage_finished = 0;
  1218.             self.super_time = 0;
  1219.         }
  1220.         if (self.super_damage_finished > time)
  1221.             self.effects = self.effects | EF_DIMLIGHT;
  1222.         else
  1223.             self.effects = self.effects - (self.effects & EF_DIMLIGHT);
  1224.     }    
  1225.  
  1226. // suit    
  1227.     if (self.radsuit_finished)
  1228.     {
  1229.         self.air_finished = time + 12;        // don't drown
  1230.  
  1231. // sound and screen flash when items starts to run out
  1232.         if (self.radsuit_finished < time + 3)
  1233.         {
  1234.             if (self.rad_time == 1)
  1235.             {
  1236.                 sprint (self, "Air supply in Biosuit expiring\n");
  1237.                 stuffcmd (self, "bf\n");
  1238.                 sound (self, CHAN_AUTO, "items/suit2.wav", 1, ATTN_NORM);
  1239.                 self.rad_time = time + 1;
  1240.             }
  1241.             
  1242.             if (self.rad_time < time)
  1243.             {
  1244.                 self.rad_time = time + 1;
  1245.                 stuffcmd (self, "bf\n");
  1246.             }
  1247.         }
  1248.  
  1249.         if (self.radsuit_finished < time)
  1250.         {    // just stopped
  1251.             self.items = self.items - IT_SUIT;
  1252.             self.rad_time = 0;
  1253.             self.radsuit_finished = 0;
  1254.         }
  1255.     }    
  1256.  
  1257. };
  1258.  
  1259.  
  1260. /*
  1261. ================
  1262. PlayerPostThink
  1263.  
  1264. Called every frame after physics are run
  1265. ================
  1266. */
  1267. void() PlayerPostThink =
  1268. {
  1269.     local    float    mspeed, aspeed;
  1270.     local    float    r;
  1271.  
  1272.     if (self.view_ofs == '0 0 0')
  1273.         return;        // intermission or finale
  1274.     if (self.deadflag)
  1275.         return;
  1276.         
  1277. // do weapon stuff
  1278.  
  1279.         W_WeaponFrame();
  1280.  
  1281. // check to see if player landed and play landing sound    
  1282.     if ((self.jump_flag < -300) && (self.flags & FL_ONGROUND) && (self.health > 0))
  1283.     {
  1284.         if (self.watertype == CONTENT_WATER)
  1285.             sound (self, CHAN_BODY, "player/h2ojump.wav", 1, ATTN_NORM);
  1286.         else if (self.jump_flag < -650)
  1287.         {
  1288.             T_Damage (self, world, world, 5); 
  1289.             sound (self, CHAN_VOICE, "player/land2.wav", 1, ATTN_NORM);
  1290.             self.deathtype = "falling";
  1291.         }
  1292.         else
  1293.             sound (self, CHAN_VOICE, "player/land.wav", 1, ATTN_NORM);
  1294.  
  1295.         self.jump_flag = 0;
  1296.     }
  1297.  
  1298.     if (!(self.flags & FL_ONGROUND))
  1299.         self.jump_flag = self.velocity_z;
  1300.  
  1301.     CheckPowerups ();
  1302. };
  1303.  
  1304.  
  1305. /*
  1306. ===========
  1307. ClientConnect
  1308.  
  1309. called when a player connects to a server
  1310. ============
  1311. */
  1312. void() ClientConnect =
  1313. {
  1314.     bprint (self.netname);
  1315.     bprint (" entered the game\n");
  1316.     
  1317. // a client connecting during an intermission can cause problems
  1318.     if (intermission_running)
  1319.         ExitIntermission ();
  1320. };
  1321.  
  1322.  
  1323. /*
  1324. ===========
  1325. ClientDisconnect
  1326.  
  1327. called when a player disconnects from a server
  1328. ============
  1329. */
  1330. void() ClientDisconnect =
  1331.    {
  1332.    local entity e, sort, walk;
  1333.    local float ppos, dflag, pnum;
  1334.  
  1335. // if the level end trigger has been activated, just return
  1336. // since they aren't *really* leaving
  1337.    if(gameover) return;
  1338.  
  1339.    if(world.chain) error("ClientDisconnect: world.chain is set");
  1340.  
  1341. // build a sorted list
  1342.    e = find(world, classname, "player");
  1343.    sort = world;
  1344.    while(e)
  1345.       {
  1346.       if(!sort)
  1347.          {
  1348.          sort = e;
  1349.          e.chain = world;
  1350.          }
  1351.       else
  1352.          {
  1353.          if(e.frags > sort.frags)
  1354.             {
  1355.             e.chain = sort;
  1356.             sort = e;
  1357.             }
  1358.          else
  1359.             {
  1360.             walk = sort;
  1361.             do
  1362.                {
  1363.                if(!walk.chain)
  1364.                   {
  1365.                   e.chain = world;
  1366.                   walk.chain = e;
  1367.                   }
  1368.                else if(walk.chain.frags < e.frags)
  1369.                   {
  1370.                   e.chain = walk.chain;
  1371.                   walk.chain = e;
  1372.                   }
  1373.                else walk = walk.chain;
  1374.                }
  1375.             while(walk.chain != e);
  1376.             }
  1377.          }
  1378.       e = find(e, classname, "player");
  1379.       }
  1380.  
  1381. // find out your position and number of players
  1382.    ppos = 0;
  1383.    dflag = 0;
  1384.    pnum = 0;
  1385.    while(sort)
  1386.       {
  1387.       if(sort == self) dflag = 1;
  1388.       sort = sort.chain;
  1389.       if(dflag == 0) ppos = ppos + 1;
  1390.       if(sort) pnum = pnum + 1;
  1391.       }
  1392. // invert
  1393.    ppos = ppos - pnum;
  1394. // scale
  1395.    ppos = ppos / pnum;
  1396.  
  1397. // print msg
  1398.    if(ppos == 1)
  1399.       {
  1400.       bprint(self.netname);
  1401.       bprint(" kicked ass with ");
  1402.       bprint(ftos(self.frags));
  1403.       bprint(" frags\n");
  1404.       }
  1405.    if(ppos < 1 && ppos >= 0.7)
  1406.       {
  1407.       bprint(self.netname);
  1408.       bprint(" left with his pride and ");
  1409.       bprint(ftos(self.frags));
  1410.       bprint(" frags\n");
  1411.       }
  1412.    if(ppos < 0.7 && ppos >= 0.3)
  1413.       {
  1414.       bprint(self.netname);
  1415.       bprint(" held his own with ");
  1416.       bprint(ftos(self.frags));
  1417.       bprint(" frags\n");
  1418.       }
  1419.    if(ppos < 0.3 && ppos > 0)
  1420.       {
  1421.       bprint(self.netname);
  1422.       bprint(" ran away with his tail between his legs and ");
  1423.       bprint(ftos(self.frags));
  1424.       bprint(" frags\n");
  1425.       }
  1426.    if(ppos == 0)
  1427.       {
  1428.       bprint(self.netname);
  1429.       bprint(" wussed out with ");
  1430.       bprint(ftos(self.frags));
  1431.       bprint(" frags\n");
  1432.       }
  1433.  
  1434. // cleanup
  1435.    sound(self, CHAN_BODY, "player/tornoff2.wav", 1, ATTN_NONE);
  1436.    set_suicide_frame();
  1437.    };
  1438.  
  1439. /*
  1440. ===========
  1441. ClientObituary
  1442.  
  1443. called when a player dies
  1444. ============
  1445. */
  1446. void(entity targ, entity attacker) ClientObituary =
  1447. {
  1448.     local    float rnum;
  1449.     local    string deathstring, deathstring2;
  1450.     rnum = random();
  1451.  
  1452.     if (targ.classname == "player")
  1453.     {
  1454.         if (attacker.classname == "teledeath")
  1455.         {
  1456.             bprint (targ.netname);
  1457.             bprint (" was telefragged by ");
  1458.             bprint (attacker.owner.netname);
  1459.             bprint ("\n");
  1460.  
  1461.             attacker.owner.frags = attacker.owner.frags + 1;
  1462.             return;
  1463.         }
  1464.  
  1465.         if (attacker.classname == "teledeath2")
  1466.         {
  1467.             bprint ("Satan's power deflects ");
  1468.             bprint (targ.netname);
  1469.             bprint ("'s telefrag\n");
  1470.  
  1471.             targ.frags = targ.frags - 1;
  1472.             return;
  1473.         }
  1474.  
  1475.         if (attacker.classname == "player")
  1476.         {
  1477.             if (targ == attacker)
  1478.             {
  1479.                 // killed self
  1480.                 attacker.frags = attacker.frags - 1;
  1481.                 bprint (targ.netname);
  1482.                 
  1483.                 if (targ.weapon == 64 && targ.waterlevel > 1)
  1484.                 {
  1485.                     bprint (" discharges into the water.\n");
  1486.                     return;
  1487.                 }
  1488.                 if (targ.weapon == 16)
  1489.                     bprint (" tries to put the pin back in\n");
  1490.                 else if (rnum)
  1491.                     bprint (" becomes bored with life\n");
  1492.                 else
  1493.                     bprint (" checks if his weapon is loaded\n");
  1494.                 return;
  1495.             }
  1496.             else
  1497.             {
  1498.                 attacker.frags = attacker.frags + 1;
  1499.  
  1500.                 rnum = attacker.weapon;
  1501.                 if (rnum == IT_AXE)
  1502.                 {
  1503.                     deathstring = " was ax-murdered by ";
  1504.                     deathstring2 = "\n";
  1505.                 }
  1506.                 if (rnum == IT_SHOTGUN)
  1507.                 {
  1508.                     deathstring = " chewed on ";
  1509.                     deathstring2 = "'s boomstick\n";
  1510.                 }
  1511.                 if (rnum == IT_SUPER_SHOTGUN)
  1512.                 {
  1513.                     deathstring = " ate 2 loads of ";
  1514.                     deathstring2 = "'s buckshot\n";
  1515.                 }
  1516.                 if (rnum == IT_NAILGUN)
  1517.                 {
  1518.                     deathstring = " was nailed by ";
  1519.                     deathstring2 = "\n";
  1520.                 }
  1521.                 if (rnum == IT_SUPER_NAILGUN)
  1522.                 {
  1523.                     deathstring = " was punctured by ";
  1524.                     deathstring2 = "\n";
  1525.                 }
  1526.                 if (rnum == IT_GRENADE_LAUNCHER)
  1527.                 {
  1528.                     deathstring = " eats ";
  1529.                     deathstring2 = "'s pineapple\n";
  1530.                     if (targ.health < -40)
  1531.                     {
  1532.                         deathstring = " was gibbed by ";
  1533.                         deathstring2 = "'s grenade\n";
  1534.                     }
  1535.                 }
  1536.                 if (rnum == IT_ROCKET_LAUNCHER)
  1537.                 {
  1538.                     deathstring = " rides ";
  1539.                     deathstring2 = "'s rocket\n";
  1540.                     if (targ.health < -40)
  1541.                     {
  1542.                         deathstring = " was gibbed by ";
  1543.                         deathstring2 = "'s rocket\n" ;
  1544.                     }
  1545.                 }
  1546.                 if (rnum == IT_LIGHTNING)
  1547.                 {
  1548.                     deathstring = " accepts ";
  1549.                     if (attacker.waterlevel > 1)
  1550.                         deathstring2 = "'s discharge\n";
  1551.                     else
  1552.                         deathstring2 = "'s shaft\n";
  1553.                 }
  1554.                 bprint (targ.netname);
  1555.                 bprint (deathstring);
  1556.                 bprint (attacker.netname);
  1557.                 bprint (deathstring2);
  1558.             }
  1559.             return;
  1560.         }
  1561.         else
  1562.         {
  1563.             targ.frags = targ.frags - 1;        // killed self
  1564.             rnum = targ.watertype;
  1565.  
  1566.             bprint (targ.netname);
  1567.             if (rnum == -3)
  1568.             {
  1569.                 if (random() < 0.5)
  1570.                     bprint (" sleeps with the fishes\n");
  1571.                 else
  1572.                     bprint (" sucks it down\n");
  1573.                 return;
  1574.             }
  1575.             else if (rnum == -4)
  1576.             {
  1577.                 if (random() < 0.5)
  1578.                     bprint (" gulped a load of slime\n");
  1579.                 else
  1580.                     bprint (" can't exist on slime alone\n");
  1581.                 return;
  1582.             }
  1583.             else if (rnum == -5)
  1584.             {
  1585.                 if (targ.health < -15)
  1586.                 {
  1587.                     bprint (" burst into flames\n");
  1588.                     return;
  1589.                 }
  1590.                 if (random() < 0.5)
  1591.                     bprint (" turned into hot slag\n");
  1592.                 else
  1593.                     bprint (" visits the Volcano God\n");
  1594.                 return;
  1595.             }
  1596.  
  1597.             if (attacker.flags & FL_MONSTER)
  1598.             {
  1599.                 if (attacker.classname == "monster_army")
  1600.                     bprint (" was shot by a Grunt\n");
  1601.                 if (attacker.classname == "monster_demon1")
  1602.                     bprint (" was eviscerated by a Fiend\n");
  1603.                 if (attacker.classname == "monster_dog")
  1604.                     bprint (" was mauled by a Rottweiler\n");
  1605.                 if (attacker.classname == "monster_dragon")
  1606.                     bprint (" was fried by a Dragon\n");
  1607.                 if (attacker.classname == "monster_enforcer")
  1608.                     bprint (" was blasted by an Enforcer\n");
  1609.                 if (attacker.classname == "monster_fish")
  1610.                     bprint (" was fed to the Rotfish\n");
  1611.                 if (attacker.classname == "monster_hell_knight")
  1612.                     bprint (" was slain by a Death Knight\n");
  1613.                 if (attacker.classname == "monster_knight")
  1614.                     bprint (" was slashed by a Knight\n");
  1615.                 if (attacker.classname == "monster_ogre")
  1616.                     bprint (" was destroyed by an Ogre\n");
  1617.                 if (attacker.classname == "monster_oldone")
  1618.                     bprint (" became one with Shub-Niggurath\n");
  1619.                 if (attacker.classname == "monster_shalrath")
  1620.                     bprint (" was exploded by a Vore\n");
  1621.                 if (attacker.classname == "monster_shambler")
  1622.                     bprint (" was smashed by a Shambler\n");
  1623.                 if (attacker.classname == "monster_tarbaby")
  1624.                     bprint (" was slimed by a Spawn\n");
  1625.                 if (attacker.classname == "monster_vomit")
  1626.                     bprint (" was vomited on by a Vomitus\n");
  1627.                 if (attacker.classname == "monster_wizard")
  1628.                     bprint (" was scragged by a Scrag\n");
  1629.                 if (attacker.classname == "monster_zombie")
  1630.                     bprint (" joins the Zombies\n");
  1631.  
  1632.                 return;
  1633.             }
  1634.             if (attacker.classname == "explo_box")
  1635.             {
  1636.                 bprint (" blew up\n");
  1637.                 return;
  1638.             }
  1639.             if (attacker.solid == SOLID_BSP && attacker != world)
  1640.             {    
  1641.                 bprint (" was squished\n");
  1642.                 return;
  1643.             }
  1644.             if (targ.deathtype == "falling")
  1645.             {
  1646.                 targ.deathtype = "";
  1647.                 bprint (" fell to his death\n");
  1648.                 return;
  1649.             }
  1650.             if (attacker.classname == "trap_shooter" || attacker.classname == "trap_spikeshooter")
  1651.             {
  1652.                 bprint (" was spiked\n");
  1653.                 return;
  1654.             }
  1655.             if (attacker.classname == "fireball")
  1656.             {
  1657.                 bprint (" ate a lavaball\n");
  1658.                 return;
  1659.             }
  1660.             if (attacker.classname == "trigger_changelevel")
  1661.             {
  1662.                 bprint (" tried to leave\n");
  1663.                 return;
  1664.             }
  1665.  
  1666.             bprint (" died\n");
  1667.         }
  1668.     }
  1669. };
  1670.  
  1671.