home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 46 / PCGAMER46.bin / Quake / QuakeC / Collect / COLLECT.EXE / SOURCES.ZIP / CLIENT.QC < prev    next >
Encoding:
Text File  |  1997-01-16  |  32.6 KB  |  1,418 lines

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