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