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