]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_physics.qc
Merge branch 'master' into Mario/physics
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_physics.qc
index 797226717cfe3129677584c626a83cabc5bd6c44..dc7c62aed537d96b79ef4a9d8665ac1988a6e88b 100644 (file)
@@ -36,15 +36,16 @@ float Physics_ClientOption(entity pl, string option)
 PlayerJump
 
 When you press the jump key
+returns TRUE if handled
 =============
 */
-void PlayerJump (void)
+float PlayerJump (void)
 {
        if(self.frozen)
-               return; // no jumping in freezetag when frozen
+               return TRUE; // no jumping in freezetag when frozen
 
        if(self.player_blocked)
-               return; // no jumping while blocked
+               return TRUE; // no jumping while blocked
 
        float doublejump = FALSE;
        float mjumpheight = self.stat_sv_jumpvelocity;
@@ -52,7 +53,7 @@ void PlayerJump (void)
        player_multijump = doublejump;
        player_jumpheight = mjumpheight;
        if(MUTATOR_CALLHOOK(PlayerJump))
-               return;
+               return TRUE;
 
        doublejump = player_multijump;
        mjumpheight = player_jumpheight;
@@ -75,16 +76,16 @@ void PlayerJump (void)
        if (self.waterlevel >= WATERLEVEL_SWIMMING)
        {
                self.velocity_z = self.stat_sv_maxspeed * 0.7;
-               return;
+               return TRUE;
        }
 
        if (!doublejump)
                if (!(self.flags & FL_ONGROUND))
-                       return;
+                       return !(self.flags & FL_JUMPRELEASED);
 
        if(self.cvar_cl_movement_track_canjump)
                if (!(self.flags & FL_JUMPRELEASED))
-                       return;
+                       return TRUE;
 
        // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
        // velocity bounds.  Final velocity is bound between (jumpheight *
@@ -143,6 +144,7 @@ void PlayerJump (void)
 
        self.restart_jump = -1; // restart jump anim next time
        // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
+       return TRUE;
 }
 void CheckWaterJump()
 {
@@ -172,11 +174,41 @@ void CheckWaterJump()
                }
        }
 }
+
+.float jetpack_stopped;
+// Hack: shouldn't need to know about this
+.float multijump_count;
 void CheckPlayerJump()
 {
-       if (self.BUTTON_JUMP)
-               PlayerJump ();
+       float was_flying = self.items & IT_USING_JETPACK;
+
+       if (self.cvar_cl_jetpack_jump < 2)
+               self.items &= ~IT_USING_JETPACK;
+
+       if (self.BUTTON_JUMP || self.BUTTON_JETPACK)
+       {
+               float air_jump = !PlayerJump() || self.multijump_count > 0; // PlayerJump() has important side effects
+               float activate = self.cvar_cl_jetpack_jump && air_jump && self.BUTTON_JUMP || self.BUTTON_JETPACK;
+               float has_fuel = !autocvar_g_jetpack_fuel || self.ammo_fuel || self.items & IT_UNLIMITED_WEAPON_AMMO;
+               if (self.jetpack_stopped) { }
+               else if (!has_fuel)
+               {
+                       if (was_flying) // TODO: ran out of fuel message
+                               Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
+                       else
+                               Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
+                       self.jetpack_stopped = TRUE;
+                       self.items &= ~IT_USING_JETPACK;
+               }
+               else if (activate && !self.frozen)
+                       self.items |= IT_USING_JETPACK;
+       }
        else
+       {
+               self.jetpack_stopped = FALSE;
+               self.items &= ~IT_USING_JETPACK;
+       }
+       if (!self.BUTTON_JUMP)
                self.flags |= FL_JUMPRELEASED;
 
        if (self.waterlevel == WATERLEVEL_SWIMMING)
@@ -794,8 +826,6 @@ void SV_PlayerPhysics()
                bot_think();
        }
 
-       self.items &= ~IT_USING_JETPACK;
-
        if(IS_PLAYER(self))
        {
                if(self.race_penalty)
@@ -1060,7 +1090,7 @@ void SV_PlayerPhysics()
                        PM_Accelerate(wishdir, wishspeed, wishspeed, self.stat_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
                }
        }
-       else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO) && !self.frozen)
+       else if (self.items & IT_USING_JETPACK)
        {
                //makevectors(self.v_angle_y * '0 1 0');
                makevectors(self.v_angle);
@@ -1133,12 +1163,11 @@ void SV_PlayerPhysics()
                else
                        fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
 
-               float fvel;
-               fvel = vlen(wishvel);
                wishvel_x *= fxy;
                wishvel_y *= fxy;
                wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
 
+               float fvel;
                fvel = min(1, vlen(wishvel) / best);
                if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
                        f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
@@ -1163,7 +1192,7 @@ void SV_PlayerPhysics()
        {
                // we get here if we ran out of ammo
                if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
-                       sprint(self, "You don't have any fuel for the ^2Jetpack\n");
+                       Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
 
                // walking
                makevectors(self.v_angle_y * '0 1 0');
@@ -1180,20 +1209,6 @@ void SV_PlayerPhysics()
                        self.jumppadcount = 0;
                }
 
-#ifdef LETS_TEST_FTEQCC
-               if(self.velocity_x || self.velocity_y)
-               {
-                       // good
-               }
-               else
-               {
-                       if(self.velocity_x)
-                               checkclient();
-                       if(self.velocity_y)
-                               checkclient();
-               }
-#endif
-
                v = self.velocity;
                v_z = 0;
                f = vlen(v);
@@ -1246,7 +1261,7 @@ void SV_PlayerPhysics()
                float wishspeed0;
                // we get here if we ran out of ammo
                if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
-                       sprint(self, "You don't have any fuel for the ^2Jetpack\n");
+                       Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
 
                if(maxspd_mod < 1)
                {
@@ -1343,15 +1358,16 @@ void SV_PlayerPhysics()
                }
        }
 
+       // WEAPONTODO
        float xyspeed;
        xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
-       if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
+       if(self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, charge_minspeed))
        {
                // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
-               xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
-               f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
+               xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
+               f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
                // add the extra charge
-               self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime);
+               self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * frametime);
        }
 :end
        if(self.flags & FL_ONGROUND)