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