]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/csqcmodel/cl_player.qc
Do not apply v_deathtilt when observing and during the intermission
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / csqcmodel / cl_player.qc
index 49011fd64a70ab94ce76cade461ad9352107d722..0b0de75649aab42d97851711fca47dd1342c8bf8 100644 (file)
 #include "cl_model.qh"
 #include "common.qh"
 #include "interpolate.qh"
-#include "../../client/defs.qh"
-#include "../../client/main.qh"
-#include "../../common/constants.qh"
-#include "../../common/physics.qh"
-#include "../../common/stats.qh"
-#include "../../common/triggers/trigger/viewloc.qh"
-#include "../../common/util.qh"
-#include "../../common/viewloc.qh"
+#include <client/defs.qh>
+#include <client/main.qh>
+#include <common/constants.qh>
+#include <common/physics/player.qh>
+#include <common/stats.qh>
+#include <common/triggers/trigger/viewloc.qh>
+#include <common/util.qh>
+#include <common/viewloc.qh>
 
 float autocvar_cl_movement_errorcompensation = 0;
-int autocvar_cl_movement = 1;
 
 // engine stuff
 float pmove_onground; // weird engine flag we shouldn't really use but have to for now
@@ -76,7 +75,7 @@ void CSQCPlayer_SetPredictionError(vector o, vector v, float onground_diff)
                return;
        }
        */
-       if(vlen(o) > 32 || vlen(v) > 192)
+       if(vdist(o, >, 32) || vdist(v, >, 192))
        {
                //printf("TOO BIG: x=%v v=%v\n", o, v);
                return;
@@ -106,17 +105,17 @@ void CSQCPlayer_Unpredict(entity this)
 
 void CSQCPlayer_SetMinsMaxs(entity this)
 {
-       if (this.flags & FL_DUCKED)
+       if ((this.flags & FL_DUCKED) || !this.isplayermodel)
        {
-               this.mins = PL_CROUCH_MIN;
-               this.maxs = PL_CROUCH_MAX;
-               this.view_ofs = PL_CROUCH_VIEW_OFS;
+               this.mins = STAT(PL_CROUCH_MIN, NULL);
+               this.maxs = STAT(PL_CROUCH_MAX, NULL);
+               this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, NULL);
        }
        else
        {
-               this.mins = PL_MIN;
-               this.maxs = PL_MAX;
-               this.view_ofs = PL_VIEW_OFS;
+               this.mins = STAT(PL_MIN, NULL);
+               this.maxs = STAT(PL_MAX, NULL);
+               this.view_ofs = STAT(PL_VIEW_OFS, NULL);
        }
 }
 
@@ -130,24 +129,71 @@ void CSQCPlayer_SavePrediction(entity this)
 }
 
 void CSQC_ClientMovement_PlayerMove_Frame(entity this);
+void _Movetype_Physics_ClientFrame(entity this, float movedt);
 
-void PM_Movement_Move(entity this)
+void Movetype_Physics_Spam(entity this)  // optimized
 {
-       runstandardplayerphysics(this);
-#ifdef CSQC
-       this.flags =
-                       ((this.pmove_flags & PMF_DUCKED) ? FL_DUCKED : 0) |
-                       (!(this.pmove_flags & PMF_JUMP_HELD) ? FL_JUMPRELEASED : 0) |
-                       ((this.pmove_flags & PMF_ONGROUND) ? FL_ONGROUND : 0);
-#endif
+       _Movetype_Physics_ClientFrame(this, PHYS_INPUT_TIMELENGTH);
+       if(wasfreed(this))
+               return;
+
+       this.avelocity = this.move_avelocity;
+       this.velocity = this.move_velocity;
+       this.angles = this.move_angles;
+       this.flags = BITSET(this.flags, FL_ONGROUND, boolean(this.move_flags & FL_ONGROUND));
+       this.flags = BITSET(this.flags, FL_WATERJUMP, boolean(this.move_flags & FL_WATERJUMP));
+       this.waterlevel = this.move_waterlevel;
+       this.watertype = this.move_watertype;
+       setorigin(this, this.move_origin);
+}
+
+void CSQCPlayer_CheckWater(entity this)
+{
+       this.move_origin = this.origin;
+       this.move_waterlevel = this.waterlevel;
+       this.move_watertype = this.watertype;
+       _Movetype_CheckWater(this);
+       this.waterlevel = this.move_waterlevel;
+       this.watertype = this.move_watertype;
 }
 
 void CSQCPlayer_Physics(entity this)
 {
-       switch (autocvar_cl_movement)
+       if(autocvar_cl_movement)
        {
-               case 1: CSQC_ClientMovement_PlayerMove_Frame(this); break;
-               case 2: PM_Movement_Move(this); break;
+               if(autocvar_cl_movement == 1)
+                       CSQCPlayer_CheckWater(this); // we apparently need to check water *before* physics so it can use this for water jump
+
+               vector oldv_angle = this.v_angle;
+               vector oldangles = this.angles; // we need to save these, as they're abused by other code
+               this.v_angle = PHYS_INPUT_ANGLES(this);
+               this.angles = PHYS_WORLD_ANGLES(this);
+
+               CSQC_ClientMovement_PlayerMove_Frame(this);
+
+               if(autocvar_cl_movement == 1)
+               {
+                       this.move_origin = this.origin;
+                       this.move_angles = this.angles;
+                       //this.move_movetype = MOVETYPE_WALK; // temp
+                       this.move_velocity = this.velocity;
+                       this.move_avelocity = this.avelocity;
+                       this.move_flags = BITSET(this.move_flags, FL_ONGROUND, IS_ONGROUND(this));
+                       this.move_flags = BITSET(this.move_flags, FL_WATERJUMP, boolean(this.flags & FL_WATERJUMP));
+                       this.move_waterlevel = this.waterlevel;
+                       this.move_watertype = this.watertype;
+                       Movetype_Physics_Spam(this);
+               }
+
+               view_angles = this.v_angle;
+               input_angles = this.angles;
+               this.v_angle = oldv_angle;
+               this.angles = oldangles;
+
+               this.pmove_flags =
+                               ((this.flags & FL_DUCKED) ? PMF_DUCKED : 0) |
+                               (!(this.flags & FL_JUMPRELEASED) ? PMF_JUMP_HELD : 0) |
+                               ((IS_ONGROUND(this)) ? PMF_ONGROUND : 0);
        }
 }
 
@@ -166,7 +212,7 @@ void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error)
 #if 0
        // we don't need this
        // darkplaces makes servercommandframe == 0 in these cases anyway
-       if (getstatf(STAT_HEALTH) <= 0)
+       if (STAT(HEALTH) <= 0)
        {
                csqcplayer_moveframe = clientcommandframe;
                getinputstate(csqcplayer_moveframe-1);
@@ -209,9 +255,9 @@ void CSQCPlayer_SetViewLocation()
 void CSQCPlayer_SetCamera()
 {
        const vector v0 = pmove_vel; // TRICK: pmove_vel is set by the engine when we get here. No need to network velocity
-       const float vh = getstati(STAT_VIEWHEIGHT);
-       const vector pl_viewofs = PL_VIEW_OFS;
-       const vector pl_viewofs_crouch = PL_CROUCH_VIEW_OFS;
+       const float vh = STAT(VIEWHEIGHT);
+       const vector pl_viewofs = STAT(PL_VIEW_OFS, NULL);
+       const vector pl_viewofs_crouch = STAT(PL_CROUCH_VIEW_OFS, NULL);
        const entity e = csqcplayer;
        if (e)
        {
@@ -246,7 +292,7 @@ void CSQCPlayer_SetCamera()
                                const vector o = e.origin;
                                csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
                                CSQCPlayer_PredictTo(e, servercommandframe + 1, false);
-                               CSQCPlayer_SetPredictionError(e.origin - o, e.velocity - v0, pmove_onground - boolean(e.flags & FL_ONGROUND));
+                               CSQCPlayer_SetPredictionError(e.origin - o, e.velocity - v0, pmove_onground - IS_ONGROUND(e));
                                e.origin = o;
                                e.velocity = v0;
 
@@ -275,7 +321,7 @@ void CSQCPlayer_SetCamera()
                setorigin(e, e.origin);
        }
 
-       const entity view = CSQCModel_server2csqc(player_localentnum);
+       const entity view = CSQCModel_server2csqc(player_localentnum - 1);
        if (view)
        {
                if (view != csqcplayer)
@@ -287,7 +333,7 @@ void CSQCPlayer_SetCamera()
                if (view.csqcmodel_teleported) refdefflags |= REFDEFFLAG_TELEPORTED;
                if (input_buttons & BIT(1)) refdefflags |= REFDEFFLAG_JUMPING;
                // note: these two only work in WIP2, but are harmless in WIP1
-               if (getstati(STAT_HEALTH) <= 0) refdefflags |= REFDEFFLAG_DEAD;
+               if (STAT(HEALTH) <= 0 && STAT(HEALTH) != -666 && STAT(HEALTH) != -2342) refdefflags |= REFDEFFLAG_DEAD;
                if (intermission) refdefflags |= REFDEFFLAG_INTERMISSION;
                V_CalcRefdef(view, refdefflags);
        }
@@ -303,7 +349,7 @@ void CSQCPlayer_SetCamera()
        CSQCPLAYER_HOOK_POSTCAMERASETUP();
 }
 
-void CSQCPlayer_Remove()
+void CSQCPlayer_Remove(entity this)
 {
        csqcplayer = NULL;
        cvar_settemp("cl_movement_replay", "1");