]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/physics.qc
Merge some changes from prediction branch
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics.qc
index b8fdb1a6c838b8415b41481f38f7733c1a1d1811..728863ad44b22b7cafd102442a96c3f4b03aa67a 100644 (file)
@@ -1,7 +1,11 @@
 #include "physics.qh"
+#include "triggers/trigger/swamp.qh"
+#include "triggers/trigger/jumppads.qh"
 
 #ifdef SVQC
 
+#include "../server/miscfunctions.qh"
+
 void Physics_AddStats()
 {
        // g_movementspeed hack
@@ -33,6 +37,7 @@ void Physics_AddStats()
        // hacks
        addstat(STAT_MOVEVARS_FRICTION_ONLAND, AS_FLOAT, stat_sv_friction_on_land);
        addstat(STAT_MOVEVARS_FRICTION_SLICK, AS_FLOAT, stat_sv_friction_slick);
+       addstat(STAT_GAMEPLAYFIX_EASIERWATERJUMP, AS_INT, stat_gameplayfix_easierwaterjump);
 }
 
 void Physics_UpdateStats(float maxspd_mod)
@@ -61,6 +66,8 @@ void Physics_UpdateStats(float maxspd_mod)
 
        self.stat_sv_friction_on_land = PHYS_FRICTION_ONLAND;
        self.stat_sv_friction_slick = PHYS_FRICTION_SLICK;
+
+       self.stat_gameplayfix_easierwaterjump = GAMEPLAYFIX_EASIERWATERJUMP;
 }
 #endif
 
@@ -115,13 +122,13 @@ void PM_ClientMovement_Unstick()
                tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
                if (!trace_startsolid)
                {
-                       self.origin = neworigin;
+                       setorigin(self, neworigin);
                        return;// true;
                }
        }
 }
 
-void PM_ClientMovement_UpdateStatus()
+void PM_ClientMovement_UpdateStatus(bool ground)
 {
        // make sure player is not stuck
        PM_ClientMovement_Unstick();
@@ -149,18 +156,20 @@ void PM_ClientMovement_UpdateStatus()
        vector origin1 = self.origin + '0 0 1';
        vector origin2 = self.origin - '0 0 1';
 
-       tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
-       if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
+       if(ground)
        {
-               SET_ONGROUND(self);
+               tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
+               if (trace_fraction < 1.0 && trace_plane_normal_z > 0.7)
+               {
+                       SET_ONGROUND(self);
 
-               // this code actually "predicts" an impact; so let's clip velocity first
-               float f = self.velocity * trace_plane_normal;
-               if (f < 0) // only if moving downwards actually
+                       // this code actually "predicts" an impact; so let's clip velocity first
+                       float f = self.velocity * trace_plane_normal;
                        self.velocity -= f * trace_plane_normal;
+               }
+               else
+                       UNSET_ONGROUND(self);
        }
-       else
-               UNSET_ONGROUND(self);
 
        // set watertype/waterlevel
        origin1 = self.origin;
@@ -191,9 +200,9 @@ void PM_ClientMovement_Move()
 #ifdef CSQC
        float t = PHYS_INPUT_TIMELENGTH;
        vector primalvelocity = self.velocity;
-       PM_ClientMovement_UpdateStatus();
+       PM_ClientMovement_UpdateStatus(false);
        float bump = 0;
-       for (bump = 0; bump < 8 && self.velocity * self.velocity > 0; bump++)
+       for (bump = 0; bump < MAX_CLIP_PLANES && (self.velocity * self.velocity) > 0; bump++)
        {
                vector neworigin = self.origin + t * self.velocity;
                tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
@@ -236,7 +245,7 @@ void PM_ClientMovement_Move()
 
                // check if it moved at all
                if (trace_fraction >= 0.001)
-                       self.origin = trace_endpos;
+                       setorigin(self, trace_endpos);
 
                // check if it moved all the way
                if (trace_fraction == 1)
@@ -276,7 +285,7 @@ void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
 
        if (dot > 0) // we can't change direction while slowing down
        {
-               k *= pow(dot, PHYS_AIRCONTROL_POWER)*PHYS_INPUT_TIMELENGTH;
+               k *= pow(dot, PHYS_AIRCONTROL_POWER) * PHYS_INPUT_TIMELENGTH;
                xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32);
                k *= PHYS_AIRCONTROL;
                self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
@@ -485,16 +494,20 @@ float PlayerJump (void)
 
        if (!WAS_ONGROUND(self))
        {
+#ifdef SVQC
                if(autocvar_speedmeter)
                        dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+#endif
                if(self.lastground < time - 0.3)
                {
                        self.velocity_x *= (1 - PHYS_FRICTION_ONLAND);
                        self.velocity_y *= (1 - PHYS_FRICTION_ONLAND);
                }
+#ifdef SVQC
                if(self.jumppadcount > 1)
                        dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
                self.jumppadcount = 0;
+#endif
        }
 
        self.velocity_z += mjumpheight;
@@ -533,11 +546,9 @@ void CheckWaterJump()
                if (trace_fraction == 1)
                {       // open at eye level
                        self.velocity_z = 225;
-#ifdef SVQC
                        self.flags |= FL_WATERJUMP;
                        SET_JUMP_HELD(self);
                        self.teleport_time = time + 2;  // safety net
-#endif
                }
        }
 }
@@ -558,20 +569,14 @@ void CheckPlayerJump()
        float was_flying = ITEMS(self) & IT_USING_JETPACK;
 #endif
        if (JETPACK_JUMP(self) < 2)
-#ifdef SVQC
                ITEMS(self) &= ~IT_USING_JETPACK;
-#endif
 
        if(PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self))
        {
-#ifdef SVQC
                float air_jump = !PlayerJump() || self.multijump_count > 0; // PlayerJump() has important side effects
                float activate = JETPACK_JUMP(self) && air_jump && PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self);
-               float has_fuel = !autocvar_g_jetpack_fuel || self.ammo_fuel || ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO;
-#else
-               PlayerJump(); // Client only
-               float has_fuel = true; // TODO
-#endif
+               float has_fuel = !PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(self) || ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO;
+
                if (!(ITEMS(self) & IT_JETPACK)) { }
                else if (self.jetpack_stopped) { }
                else if (!has_fuel)
@@ -583,21 +588,15 @@ void CheckPlayerJump()
                                Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
 #endif
                        self.jetpack_stopped = true;
-#ifdef SVQC
                        ITEMS(self) &= ~IT_USING_JETPACK;
-#endif
                }
-#ifdef SVQC
                else if (activate && !PHYS_FROZEN(self))
                        ITEMS(self) |= IT_USING_JETPACK;
-#endif
        }
        else
        {
                self.jetpack_stopped = false;
-#ifdef SVQC
                ITEMS(self) &= ~IT_USING_JETPACK;
-#endif
        }
        if (!PHYS_INPUT_BUTTON_JUMP(self))
                UNSET_JUMP_HELD(self);
@@ -984,6 +983,33 @@ void PM_check_frozen(void)
        }
 }
 
+void PM_check_hitground()
+{
+#ifdef SVQC
+       if (IS_ONGROUND(self))
+       if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
+       if (self.wasFlying)
+       {
+               self.wasFlying = 0;
+               if (self.waterlevel < WATERLEVEL_SWIMMING)
+               if (time >= self.ladder_time)
+               if (!self.hook)
+               {
+                       self.nextstep = time + 0.3 + random() * 0.1;
+                       trace_dphitq3surfaceflags = 0;
+                       tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
+                       if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
+                       {
+                               if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
+                                       GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+                               else
+                                       GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+                       }
+               }
+       }
+#endif
+}
+
 void PM_check_blocked(void)
 {
 #ifdef SVQC
@@ -997,12 +1023,11 @@ void PM_check_blocked(void)
 #ifdef SVQC
 float speedaward_lastsent;
 float speedaward_lastupdate;
-string GetMapname(void);
 #endif
 void PM_check_race(void)
 {
 #ifdef SVQC
-       if not(g_cts || g_race)
+       if(!(g_cts || g_race))
                return;
        if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
        {
@@ -1199,18 +1224,6 @@ void PM_ladder(float maxspd_mod)
                PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
 }
 
-void PM_check_jumppad()
-{
-#ifdef CSQC
-       entity oldself = self;
-
-       for(self = world; (self = find(self, classname, "jumppad")); )
-               trigger_push_draw();
-
-       self = oldself;
-#endif
-}
-
 void PM_jetpack(float maxspd_mod)
 {
        //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
@@ -1326,196 +1339,24 @@ void PM_jetpack(float maxspd_mod)
                        self.velocity_z -= g * 0.5;
 #endif
 }
-#ifdef SVQC
-void SV_WalkMove ()
-{
-       // if PHYS_INPUT_TIMELENGTH is 0 (due to client sending the same timestamp twice),
-       // don't move
-       if (PHYS_INPUT_TIMELENGTH <= 0)
-               return;
-
-//     if (autocvar_sv_gameplayfix_unstickplayers)
-//             SV_CheckStuck (self);
-
-//     applygravity = !SV_CheckWater(self) && self.movetype == MOVETYPE_WALK && !(self.flags & FL_WATERJUMP);
-
-//     hitsupercontentsmask = SV_GenericHitSuperContentsMask(self);
-
-//     SV_CheckVelocity(self);
-
-       // do a regular slide move unless it looks like you ran into a step
-//     float oldonground = self.flags & FL_ONGROUND;
-
-       vector start_origin = self.origin;
-       vector start_velocity = self.velocity;
-
-       float clip = 0;
-//     clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, NULL, hitsupercontentsmask, sv_gameplayfix_stepmultipletimes.integer ? sv_stepheight.value : 0);
-
-//     if(sv_gameplayfix_downtracesupportsongroundflag.integer)
-//     if(!(clip & 1))
-       {
-               // only try this if there was no floor in the way in the trace (no,
-               // this check seems to be not REALLY necessary, because if clip & 1,
-               // our trace will hit that thing too)
-               vector upmove = self.origin;
-               upmove_z++;
-               vector downmove = self.origin;
-               upmove_z--;
-               float type;
-               if (self.movetype == MOVETYPE_FLYMISSILE)
-                       type = MOVE_MISSILE;
-               else if (self.movetype == MOVETYPE_FLY_WORLDONLY)
-                       type = MOVE_WORLDONLY;
-               else if (self.solid == SOLID_TRIGGER || self.solid == SOLID_NOT)
-                       type = MOVE_NOMONSTERS; // only clip against bmodels
-               else
-                       type = MOVE_NORMAL;
-               vector entmins = self.mins;
-               vector entmaxs = self.maxs;
-               tracebox(upmove, entmins, entmaxs, downmove, type, self);
-               if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
-                       clip |= 1; // but we HAVE found a floor
-       }
-
-       // if the move did not hit the ground at any point, we're not on ground
-//     if(!(clip & 1))
-//             self.flags = self.flags & ~FL_ONGROUND;
-
-//     SV_CheckVelocity(self);
-//     SV_LinkEdict(self);
-//     SV_LinkEdict_TouchAreaGrid(self);
-
-       if(clip & 8) // teleport
-               return;
-
-       if (self.flags & FL_WATERJUMP)
-               return;
 
-//     if (autocvar_sv_nostep)
-//             return;
-
-       vector originalmove_origin = self.origin;
-       vector originalmove_velocity = self.velocity;
-       float originalmove_flags = self.flags;
-       entity originalmove_groundentity = self.groundentity;
-
-       // if move didn't block on a step, return
-       if (clip & 2)
-       {
-               // if move was not trying to move into the step, return
-               if (fabs(start_velocity_x) < 0.03125 && fabs(start_velocity_y) < 0.03125)
-                       return;
-
-               if (self.movetype != MOVETYPE_FLY)
-               {
-                       // return if gibbed by a trigger
-                       if (self.movetype != MOVETYPE_WALK)
-                               return;
-
-                       // return if attempting to jump while airborn (unless sv_jumpstep)
-//                     if (!autocvar_sv_jumpstep)
-//                             if (!oldonground && PRVM_serveredictfloat(self, waterlevel) == 0)
-//                                     return;
-               }
-
-               // try moving up and forward to go up a step
-               // back to start pos
-               self.origin = start_origin;
-               self.velocity = start_velocity;
-
-               // move up
-               vector upmove = '0 0 0';
-               upmove_z = autocvar_sv_stepheight;
-//             if(!SV_PushEntity(&trace, self, upmove, true))
-//             {
-//                     // we got teleported when upstepping... must abort the move
-//                     return;
-//             }
-
-               // move forward
-               self.velocity_z = 0;
-//             clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, stepnormal, hitsupercontentsmask, 0);
-               self.velocity_z += start_velocity_z;
-//             if(clip & 8)
-//             {
-//                     // we got teleported when upstepping... must abort the move
-//                     // note that z velocity handling may not be what QC expects here, but we cannot help it
-//                     return;
-//             }
-
-//             SV_CheckVelocity(self);
-//             SV_LinkEdict(self);
-//             SV_LinkEdict_TouchAreaGrid(self);
-
-               // check for stuckness, possibly due to the limited precision of floats
-               // in the clipping hulls
-               if (clip
-                && fabs(originalmove_origin_y - self.origin_y < 0.03125)
-                && fabs(originalmove_origin_x - self.origin_x < 0.03125))
-               {
-                       //Con_Printf("wall\n");
-                       // stepping up didn't make any progress, revert to original move
-                       self.origin = originalmove_origin;
-                       self.velocity = originalmove_velocity;
-                       self.flags = originalmove_flags;
-                       self.groundentity = originalmove_groundentity;
-                       return;
-               }
-
-               //Con_Printf("step - ");
-
-               // extra friction based on view angle
-//             if (clip & 2 && sv_wallfriction.integer)
-//                     SV_WallFriction (self, stepnormal);
-       }
-       // don't do the down move if stepdown is disabled, moving upward, not in water, or the move started offground or ended onground
-//     else if (!autocvar_sv_gameplayfix_stepdown || self.waterlevel >= 3 || start_velocity_z >= (1.0 / 32.0) || !oldonground || (self.flags & FL_ONGROUND))
-//             return;
-
-       // move down
-       vector downmove = '0 0 0';
-       downmove_z = -autocvar_sv_stepheight + start_velocity_z*PHYS_INPUT_TIMELENGTH;
-//     if(!SV_PushEntity (&downtrace, self, downmove, true))
-//     {
-//             // we got teleported when downstepping... must abort the move
-//             return;
-//     }
-
-       if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
-       {
-               // this has been disabled so that you can't jump when you are stepping
-               // up while already jumping (also known as the Quake2 double jump bug)
-       }
-       else
-       {
-               //Con_Printf("slope\n");
-               // if the push down didn't end up on good ground, use the move without
-               // the step up.  This happens near wall / slope combinations, and can
-               // cause the player to hop up higher on a slope too steep to climb
-               self.origin = originalmove_origin;
-               self.velocity = originalmove_velocity;
-               self.flags = originalmove_flags;
-               self.groundentity = originalmove_groundentity;
-       }
-
-//     SV_CheckVelocity(self);
-//     SV_LinkEdict(self);
-//     SV_LinkEdict_TouchAreaGrid(self);
-}
-#endif
 void PM_walk(float buttons_prev, float maxspd_mod)
 {
        if (!WAS_ONGROUND(self))
        {
+#ifdef SVQC
                if (autocvar_speedmeter)
                        dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+#endif
                if (self.lastground < time - 0.3)
                        self.velocity *= (1 - PHYS_FRICTION_ONLAND);
+#ifdef SVQC
                if (self.jumppadcount > 1)
                        dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
                self.jumppadcount = 0;
+#endif
        }
+
        // walking
        makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
        vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
@@ -1658,26 +1499,32 @@ void PM_air(float buttons_prev, float maxspd_mod)
 }
 
 // used for calculating airshots
-float PM_is_flying()
+bool IsFlying(entity a)
 {
-       if (IS_ONGROUND(self))
-               return 0;
-       if (self.waterlevel >= WATERLEVEL_SWIMMING)
-               return 0;
-       traceline(self.origin, self.origin - '0 0 48', MOVE_NORMAL, self);
-       return trace_fraction >= 1;
+       if(IS_ONGROUND(a))
+               return false;
+       if(a.waterlevel >= WATERLEVEL_SWIMMING)
+               return false;
+       traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
+       if(trace_fraction < 1)
+               return false;
+       return true;
 }
 
 void PM_Main()
 {
        float buttons = PHYS_INPUT_BUTTON_MASK(self);
 #ifdef CSQC
+       self.items = getstati(STAT_ITEMS, 0, 24);
+
        self.team = myteam + 1; // is this correct?
        if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump
                UNSET_JUMP_HELD(self); // canjump = true
        pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
+
+       PM_ClientMovement_UpdateStatus(true);
 #endif
-       PM_ClientMovement_UpdateStatus();
+       
 
 #ifdef SVQC
        WarpZone_PlayerPhysics_FixVAngle();
@@ -1777,11 +1624,8 @@ void PM_Main()
 
        maxspeed_mod = 1;
 
-#ifdef SVQC
-       if (self.in_swamp) {
+       if (self.in_swamp)
                maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
-       }
-#endif
 
        // conveyors: first fix velocity
        if (self.conveyor.state)
@@ -1829,59 +1673,29 @@ void PM_Main()
        }
 #endif
 
-#ifdef SVQC
-       // if dead, behave differently
-       // in CSQC, physics don't handle dead player
-       if (self.deadflag)
+       if(PHYS_DEAD(self))
                goto end;
-#endif
 
 #ifdef SVQC
        if (!self.fixangle && !g_bugrigs)
                self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
 #endif
 
-#ifdef SVQC
-       if (IS_ONGROUND(self))
-       if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
-       if (self.wasFlying)
-       {
-               self.wasFlying = 0;
-               if (self.waterlevel < WATERLEVEL_SWIMMING)
-               if (time >= self.ladder_time)
-               if (!self.hook)
-               {
-                       self.nextstep = time + 0.3 + random() * 0.1;
-                       trace_dphitq3surfaceflags = 0;
-                       tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
-                       if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
-                       {
-                               if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
-                                       GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
-                               else
-                                       GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
-                       }
-               }
-       }
-#endif
+       PM_check_hitground();
 
-       if (PM_is_flying())
+       if(IsFlying(self))
                self.wasFlying = 1;
 
-#ifdef SVQC
        if (IS_PLAYER(self))
-#endif
                CheckPlayerJump();
 
-       PM_check_jumppad();
-
-       if (self.flags & /* FL_WATERJUMP */ 2048)
+       if (self.flags & FL_WATERJUMP)
        {
                self.velocity_x = self.movedir_x;
                self.velocity_y = self.movedir_y;
                if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
                {
-                       self.flags &= ~/* FL_WATERJUMP */ 2048;
+                       self.flags &= ~FL_WATERJUMP;
                        self.teleport_time = 0;
                }
        }
@@ -1903,13 +1717,11 @@ void PM_Main()
        else if (ITEMS(self) & IT_USING_JETPACK)
                PM_jetpack(maxspeed_mod);
 
+       else if (IS_ONGROUND(self))
+               PM_walk(buttons_prev, maxspeed_mod);
+
        else
-       {
-               if (IS_ONGROUND(self))
-                       PM_walk(buttons_prev, maxspeed_mod);
-               else
-                       PM_air(buttons_prev, maxspeed_mod);
-       }
+               PM_air(buttons_prev, maxspeed_mod);
 
 #ifdef SVQC
        if (!IS_OBSERVER(self))
@@ -1922,14 +1734,10 @@ void PM_Main()
                self.lastground = time;
 
        // conveyors: then break velocity again
-       if (self.conveyor.state)
+       if(self.conveyor.state)
                self.velocity += self.conveyor.movedir;
 
-#ifdef SVQC
        self.lastflags = self.flags;
-#elif defined(CSQC)
-       self.lastflags = self.pmove_flags;
-#endif
 
        self.lastclassname = self.classname;
 }
@@ -1941,4 +1749,8 @@ void CSQC_ClientMovement_PlayerMove_Frame(void)
 #endif
 {
        PM_Main();
+
+#ifdef CSQC
+       self.pmove_flags = self.flags; // TODO
+#endif
 }