]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_user.c
***map loader generates portals for the map*** (can you tell this is a big deal? :)
[xonotic/darkplaces.git] / sv_user.c
index 303d6ede02cd350bc833e9013f22a820993efd0d..496d0c02126ca6c65758f99423481002987e7bfe 100644 (file)
--- a/sv_user.c
+++ b/sv_user.c
@@ -25,6 +25,7 @@ edict_t       *sv_player;
 
 extern cvar_t  sv_friction;
 cvar_t sv_edgefriction = {"edgefriction", "2"};
+cvar_t sv_predict = {"sv_predict", "1"};
 extern cvar_t  sv_stopspeed;
 
 static vec3_t          forward, right, up;
@@ -148,7 +149,7 @@ void SV_UserFriction (void)
 
 // apply friction      
        control = speed < sv_stopspeed.value ? sv_stopspeed.value : speed;
-       newspeed = speed - host_frametime*control*friction;
+       newspeed = speed - sv.frametime*control*friction;
        
        if (newspeed < 0)
                newspeed = 0;
@@ -180,7 +181,7 @@ void SV_Accelerate (vec3_t wishvel)
        VectorSubtract (wishvel, velocity, pushvec);
        addspeed = VectorNormalize (pushvec);
 
-       accelspeed = sv_accelerate.value*host_frametime*addspeed;
+       accelspeed = sv_accelerate.value*sv.frametime*addspeed;
        if (accelspeed > addspeed)
                accelspeed = addspeed;
        
@@ -197,7 +198,7 @@ void SV_Accelerate (void)
        addspeed = wishspeed - currentspeed;
        if (addspeed <= 0)
                return;
-       accelspeed = sv_accelerate.value*host_frametime*wishspeed;
+       accelspeed = sv_accelerate.value*sv.frametime*wishspeed;
        if (accelspeed > addspeed)
                accelspeed = addspeed;
        
@@ -217,8 +218,8 @@ void SV_AirAccelerate (vec3_t wishveloc)
        addspeed = wishspd - currentspeed;
        if (addspeed <= 0)
                return;
-//     accelspeed = sv_accelerate.value * host_frametime;
-       accelspeed = sv_accelerate.value*wishspeed * host_frametime;
+//     accelspeed = sv_accelerate.value * sv.frametime;
+       accelspeed = sv_accelerate.value*wishspeed * sv.frametime;
        if (accelspeed > addspeed)
                accelspeed = addspeed;
        
@@ -230,13 +231,24 @@ void SV_AirAccelerate (vec3_t wishveloc)
 void DropPunchAngle (void)
 {
        float   len;
+       eval_t  *val;
        
        len = VectorNormalizeLength (sv_player->v.punchangle);
        
-       len -= 10*host_frametime;
+       len -= 10*sv.frametime;
        if (len < 0)
                len = 0;
        VectorScale (sv_player->v.punchangle, len, sv_player->v.punchangle);
+       
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_punchvector)))
+       {
+               len = VectorNormalizeLength (val->vector);
+               
+               len -= 20*sv.frametime;
+               if (len < 0)
+                       len = 0;
+               VectorScale (val->vector, len, val->vector);
+       }
 }
 
 /*
@@ -278,7 +290,7 @@ void SV_WaterMove (void)
        speed = Length (velocity);
        if (speed)
        {
-               newspeed = speed - host_frametime * speed * sv_friction.value;
+               newspeed = speed - sv.frametime * speed * sv_friction.value;
                if (newspeed < 0)
                        newspeed = 0;   
                VectorScale (velocity, newspeed/speed, velocity);
@@ -297,7 +309,7 @@ void SV_WaterMove (void)
                return;
 
        VectorNormalize (wishvel);
-       accelspeed = sv_accelerate.value * wishspeed * host_frametime;
+       accelspeed = sv_accelerate.value * wishspeed * sv.frametime;
        if (accelspeed > addspeed)
                accelspeed = addspeed;
 
@@ -428,8 +440,7 @@ void SV_ClientThink (void)
 //
 // walk
 //
-       if ( (sv_player->v.waterlevel >= 2)
-       && (sv_player->v.movetype != MOVETYPE_NOCLIP) )
+       if ( (sv_player->v.waterlevel >= 2)     && (sv_player->v.movetype != MOVETYPE_NOCLIP) )
        {
                SV_WaterMove ();
                return;
@@ -456,16 +467,26 @@ void SV_ReadClientMove (usercmd_t *move)
        host_client->ping_times[host_client->num_pings%NUM_PING_TIMES]
                = sv.time - MSG_ReadFloat ();
        host_client->num_pings++;
-       if (val = GETEDICTFIELDVALUE(host_client->edict, eval_ping))
+       for (i=0, total = 0;i < NUM_PING_TIMES;i++)
+               total += host_client->ping_times[i];
+       host_client->ping = total / NUM_PING_TIMES; // can be used for prediction
+       host_client->latency = 0;
+       if (sv_predict.value && (svs.maxclients > 1) && (!sv.paused)) // if paused or a local game, don't predict
+               host_client->latency = host_client->ping;
+       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ping)))
+               val->_float = host_client->ping * 1000.0;
+
+// read current angles
+       if (dpprotocol)
        {
-               for (i=0, total = 0;i < NUM_PING_TIMES;i++)
-                       total += host_client->ping_times[i];
-               val->_float = 1000.0 / NUM_PING_TIMES;
+               for (i=0 ; i<3 ; i++)
+                       angle[i] = MSG_ReadPreciseAngle ();
+       }
+       else
+       {
+               for (i=0 ; i<3 ; i++)
+                       angle[i] = MSG_ReadAngle ();
        }
-
-// read current angles 
-       for (i=0 ; i<3 ; i++)
-               angle[i] = MSG_ReadAngle ();
 
        VectorCopy (angle, host_client->edict->v.v_angle);
                
@@ -473,7 +494,7 @@ void SV_ReadClientMove (usercmd_t *move)
        move->forwardmove = MSG_ReadShort ();
        move->sidemove = MSG_ReadShort ();
        move->upmove = MSG_ReadShort ();
-       if (val = GETEDICTFIELDVALUE(host_client->edict, eval_movement))
+       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_movement)))
        {
                val->vector[0] = move->forwardmove;
                val->vector[1] = move->sidemove;
@@ -485,12 +506,12 @@ void SV_ReadClientMove (usercmd_t *move)
        host_client->edict->v.button0 = bits & 1;
        host_client->edict->v.button2 = (bits & 2)>>1;
        // LordHavoc: added 6 new buttons
-       if (val = GETEDICTFIELDVALUE(host_client->edict, eval_button3)) val->_float = ((bits >> 2) & 1);
-       if (val = GETEDICTFIELDVALUE(host_client->edict, eval_button4)) val->_float = ((bits >> 3) & 1);
-       if (val = GETEDICTFIELDVALUE(host_client->edict, eval_button5)) val->_float = ((bits >> 4) & 1);
-       if (val = GETEDICTFIELDVALUE(host_client->edict, eval_button6)) val->_float = ((bits >> 5) & 1);
-       if (val = GETEDICTFIELDVALUE(host_client->edict, eval_button7)) val->_float = ((bits >> 6) & 1);
-       if (val = GETEDICTFIELDVALUE(host_client->edict, eval_button8)) val->_float = ((bits >> 7) & 1);
+       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button3))) val->_float = ((bits >> 2) & 1);
+       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button4))) val->_float = ((bits >> 3) & 1);
+       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button5))) val->_float = ((bits >> 4) & 1);
+       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button6))) val->_float = ((bits >> 5) & 1);
+       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button7))) val->_float = ((bits >> 6) & 1);
+       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button8))) val->_float = ((bits >> 7) & 1);
 
        i = MSG_ReadByte ();
        if (i)
@@ -552,10 +573,7 @@ nextmsg:
                                
                        case clc_stringcmd:     
                                s = MSG_ReadString ();
-                               if (host_client->privileged)
-                                       ret = 2;
-                               else
-                                       ret = 0;
+                               ret = 0;
                                if (Q_strncasecmp(s, "status", 6) == 0
                                 || Q_strncasecmp(s, "name", 4) == 0
                                 || Q_strncasecmp(s, "say", 3) == 0
@@ -573,13 +591,20 @@ nextmsg:
                                 || Q_strncasecmp(s, "pmodel", 6) == 0
                                 || (nehahra && (Q_strncasecmp(s, "max", 3) == 0 || Q_strncasecmp(s, "monster", 7) == 0 || Q_strncasecmp(s, "scrag", 5) == 0 || Q_strncasecmp(s, "gimme", 5) == 0 || Q_strncasecmp(s, "wraith", 6) == 0))
                                 || (!nehahra && (Q_strncasecmp(s, "god", 3) == 0 || Q_strncasecmp(s, "notarget", 8) == 0 || Q_strncasecmp(s, "fly", 3) == 0 || Q_strncasecmp(s, "give", 4) == 0 || Q_strncasecmp(s, "noclip", 6) == 0)))
+                               {
                                        ret = 1;
+                                       Cmd_ExecuteString (s, src_client);
+                               }
+                               else
+                                       Con_DPrintf("%s tried to %s\n", host_client->name, s);
+                               /*
                                if (ret == 2)
                                        Cbuf_InsertText (s);
                                else if (ret == 1)
                                        Cmd_ExecuteString (s, src_client);
                                else
                                        Con_DPrintf("%s tried to %s\n", host_client->name, s);
+                               */
                                break;
                                
                        case clc_disconnect:
@@ -635,7 +660,7 @@ void SV_RunClients (void)
                        {
                                pr_global_struct->time = sv.time;
                                pr_global_struct->self = EDICT_TO_PROG(sv_player);
-                               PR_ExecuteProgram ((func_t)(SV_PlayerPhysicsQC - pr_functions));
+                               PR_ExecuteProgram ((func_t)(SV_PlayerPhysicsQC - pr_functions), "");
                        }
                        else
                                SV_ClientThink ();