]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move multijump to the mutator system
authorMario <mario.mario@y7mail.com>
Thu, 6 Jun 2013 06:52:31 +0000 (16:52 +1000)
committerMario <mario.mario@y7mail.com>
Thu, 6 Jun 2013 06:52:31 +0000 (16:52 +1000)
qcsrc/server/cl_physics.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/base.qh
qcsrc/server/mutators/mutator_multijump.qc [new file with mode: 0644]
qcsrc/server/mutators/mutators.qh
qcsrc/server/progs.src

index 002c187812c70a727bc5c7a58ee7b0414c914894..5424f1d8a11f31c64bafe06440915fa9b53dfe9e 100644 (file)
 .float wasFlying;
 .float spectatorspeed;
 
-.float multijump_count;
-.float multijump_ready;
-.float prevjumpbutton;
-
 /*
 =============
 PlayerJump
@@ -23,13 +19,16 @@ When you press the jump key
 */
 void PlayerJump (void)
 {
+       float doublejump = FALSE;
+
+       player_multijump = doublejump;
        if(MUTATOR_CALLHOOK(PlayerJump))
                return;
+               
+       doublejump = player_multijump;
 
        float mjumpheight;
-       float doublejump;
-
-       doublejump = FALSE;
+       
        if (autocvar_sv_doublejump)
        {
                tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
@@ -52,56 +51,6 @@ void PlayerJump (void)
                return;
        }
 
-       if (autocvar_g_multijump)
-       {
-               if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
-                       self.multijump_ready = TRUE;  // this is necessary to check that we released the jump button and pressed it again
-               else
-                       self.multijump_ready = FALSE;
-       }
-
-       if(!doublejump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed)
-       {
-               // doublejump = FALSE; // checked above in the if
-               if (autocvar_g_multijump)
-               {
-                       if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
-                       {
-                               if (self.velocity_z < mjumpheight)
-                               {
-                                       doublejump = TRUE;
-                                       self.velocity_z = 0;
-                               }
-                       }
-                       else
-                               doublejump = TRUE;
-
-                       if(doublejump)
-                       {
-                               if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
-                               {
-                                       float curspeed;
-                                       vector wishvel, wishdir;
-
-                                       curspeed = max(
-                                               vlen(vec2(self.velocity)), // current xy speed
-                                               vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
-                                       );
-                                       makevectors(self.v_angle_y * '0 1 0');
-                                       wishvel = v_forward * self.movement_x + v_right * self.movement_y;
-                                       wishdir = normalize(wishvel);
-
-                                       self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
-                                       self.velocity_y = wishdir_y * curspeed;
-                                       // keep velocity_z unchanged!
-                               }
-                               if (autocvar_g_multijump > 0)
-                                       self.multijump_count += 1;
-                       }
-               }
-               self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
-       }
-
        if (!doublejump)
                if (!(self.flags & FL_ONGROUND))
                        return;
@@ -198,14 +147,6 @@ void CheckWaterJump()
 }
 void CheckPlayerJump()
 {
-       if(self.flags & FL_ONGROUND)
-       {
-               if (autocvar_g_multijump > 0)
-                       self.multijump_count = 0;
-               else
-                       self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
-       }
-
        if (self.BUTTON_JUMP)
                PlayerJump ();
        else
@@ -213,7 +154,6 @@ void CheckPlayerJump()
 
        if (self.waterlevel == WATERLEVEL_SWIMMING)
                CheckWaterJump ();
-       self.prevjumpbutton = self.BUTTON_JUMP;
 }
 
 float racecar_angle(float forward, float down)
index 76885d3ed95c03290acc0b69994bcb56e28568e5..c55819704e2005fb4a6d070431d84d5dae0e6b8d 100644 (file)
@@ -923,6 +923,7 @@ void readlevelcvars(void)
        CHECK_MUTATOR_ADD("g_bloodloss", mutator_bloodloss, !cvar("g_minstagib"));
        CHECK_MUTATOR_ADD("g_random_gravity", mutator_random_gravity, 1);
        CHECK_MUTATOR_ADD("g_norecoil", mutator_norecoil, 1);
+       CHECK_MUTATOR_ADD("g_multijump", mutator_multijump, 1);
        CHECK_MUTATOR_ADD("g_sandbox", sandbox, 1);
        
        #undef CHECK_MUTATOR_ADD
index 13fd07e3db8b68373e6eb3d7fe250efc8a4dcaa2..98a44944dd7d7c84c3c4c0a478e97b14c02203d8 100644 (file)
@@ -75,6 +75,8 @@ MUTATOR_HOOKABLE(PlayerDies);
                
 MUTATOR_HOOKABLE(PlayerJump);
        // called when a player presses the jump key
+       // INPUT, OUTPUT:
+               float player_multijump;
 
 MUTATOR_HOOKABLE(GiveFragsForKill);
        // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
diff --git a/qcsrc/server/mutators/mutator_multijump.qc b/qcsrc/server/mutators/mutator_multijump.qc
new file mode 100644 (file)
index 0000000..c945e1c
--- /dev/null
@@ -0,0 +1,88 @@
+.float multijump_count;
+.float multijump_ready;
+
+MUTATOR_HOOKFUNCTION(multijump_PlayerPhysics)
+{
+       if(self.flags & FL_ONGROUND)
+       {
+               if (autocvar_g_multijump > 0)
+                       self.multijump_count = 0;
+               else
+                       self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
+       }
+               
+       return FALSE;
+}
+
+MUTATOR_HOOKFUNCTION(multijump_PlayerJump)
+{
+       if (self.flags & FL_JUMPRELEASED && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
+               self.multijump_ready = TRUE;  // this is necessary to check that we released the jump button and pressed it again
+       else
+               self.multijump_ready = FALSE;
+               
+       if(!player_multijump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed)
+       {
+               if (autocvar_g_multijump)
+               {
+                       if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
+                       {
+                               if (self.velocity_z < autocvar_sv_jumpvelocity)
+                               {
+                                       player_multijump = TRUE;
+                                       self.velocity_z = 0;
+                               }
+                       }
+                       else
+                               player_multijump = TRUE;
+
+                       if(player_multijump)
+                       {
+                               if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
+                               {
+                                       float curspeed;
+                                       vector wishvel, wishdir;
+
+                                       curspeed = max(
+                                               vlen(vec2(self.velocity)), // current xy speed
+                                               vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
+                                       );
+                                       makevectors(self.v_angle_y * '0 1 0');
+                                       wishvel = v_forward * self.movement_x + v_right * self.movement_y;
+                                       wishdir = normalize(wishvel);
+
+                                       self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
+                                       self.velocity_y = wishdir_y * curspeed;
+                                       // keep velocity_z unchanged!
+                               }
+                               if (autocvar_g_multijump > 0)
+                                       self.multijump_count += 1;
+                       }
+               }
+               self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
+       }
+
+       return FALSE;
+}
+
+MUTATOR_HOOKFUNCTION(multijump_BuildMutatorsString)
+{
+       ret_string = strcat(ret_string, ":multijump");
+       return FALSE;
+}
+
+MUTATOR_HOOKFUNCTION(multijump_BuildMutatorsPrettyString)
+{
+       ret_string = strcat(ret_string, ", Multi jump");
+       return FALSE;
+}
+
+MUTATOR_DEFINITION(mutator_multijump)
+{
+       MUTATOR_HOOK(PlayerPhysics, multijump_PlayerPhysics, CBC_ORDER_ANY);
+       MUTATOR_HOOK(PlayerJump, multijump_PlayerJump, CBC_ORDER_ANY);
+       MUTATOR_HOOK(BuildMutatorsString, multijump_BuildMutatorsString, CBC_ORDER_ANY);
+       MUTATOR_HOOK(BuildMutatorsPrettyString, multijump_BuildMutatorsPrettyString, CBC_ORDER_ANY);
+
+       return FALSE;
+}
index ef3a7e9c9988201c2d3a131702eae0226f72643b..34e96a00fbb63b03706ea113e2e552f32e1b8cd5 100644 (file)
@@ -26,5 +26,6 @@ MUTATOR_DECLARATION(mutator_midair);
 MUTATOR_DECLARATION(mutator_bloodloss);
 MUTATOR_DECLARATION(mutator_random_gravity);
 MUTATOR_DECLARATION(mutator_norecoil);
+MUTATOR_DECLARATION(mutator_multijump);
 
 MUTATOR_DECLARATION(sandbox);
index e16e4e969a809fce1e66e548aa2264c1fcf5e5ae..d4a98e6d1654a8241fece9b98ebbe254e33089bd 100644 (file)
@@ -253,6 +253,7 @@ mutators/mutator_midair.qc
 mutators/mutator_bloodloss.qc
 mutators/mutator_random_gravity.qc
 mutators/mutator_norecoil.qc
+mutators/mutator_multijump.qc
 
 ../warpzonelib/anglestransform.qc
 ../warpzonelib/mathlib.qc