home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / tf1_1src / client.qc < prev    next >
Encoding:
Text File  |  1996-08-30  |  36.4 KB  |  1,636 lines

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