]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/multijump/multijump.qc
Merge branch 'master' into cloudwalk9/mgburstfix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / multijump / multijump.qc
index c4a2e40fcd0c55ff9fd8523cb63e3a06e6a8be49..0efd85635cc88503b9998675c59eaf2369fd347c 100644 (file)
@@ -1,4 +1,7 @@
-#ifdef IMPLEMENTATION
+#include "multijump.qh"
+
+#ifdef GAMEQC
+
 #ifdef SVQC
        #include <server/antilag.qh>
 #endif
 
 
 #if defined(SVQC)
-REGISTER_MUTATOR(multijump, cvar("g_multijump"));
+REGISTER_MUTATOR(multijump, autocvar_g_multijump);
 #elif defined(CSQC)
 REGISTER_MUTATOR(multijump, true);
 #endif
 
-#define PHYS_MULTIJUMP                                 STAT(MULTIJUMP, self)
-#define PHYS_MULTIJUMP_SPEED           STAT(MULTIJUMP_SPEED, self)
-#define PHYS_MULTIJUMP_ADD                     STAT(MULTIJUMP_ADD, self)
-#define PHYS_MULTIJUMP_MAXSPEED        STAT(MULTIJUMP_MAXSPEED, self)
-#define PHYS_MULTIJUMP_DODGING                 STAT(MULTIJUMP_DODGING, self)
-#define PHYS_MULTIJUMP_COUNT(s)        STAT(MULTIJUMP_COUNT, s)
+#define PHYS_MULTIJUMP(s)                              STAT(MULTIJUMP, s)
+#define PHYS_MULTIJUMP_SPEED(s)                STAT(MULTIJUMP_SPEED, s)
+#define PHYS_MULTIJUMP_ADD(s)                  STAT(MULTIJUMP_ADD, s)
+#define PHYS_MULTIJUMP_MAXSPEED(s)             STAT(MULTIJUMP_MAXSPEED, s)
+#define PHYS_MULTIJUMP_DODGING(s)              STAT(MULTIJUMP_DODGING, s)
+#define PHYS_MULTIJUMP_COUNT(s)                STAT(MULTIJUMP_COUNT, s)
 
 .bool multijump_ready;
 
 #ifdef CSQC
+bool cvar_cl_multijump;
 bool autocvar_cl_multijump = true;
 
        #define PHYS_MULTIJUMP_CLIENT(s)        autocvar_cl_multijump
 #elif defined(SVQC)
 .bool cvar_cl_multijump;
 
-       #define PHYS_MULTIJUMP_CLIENT(s)        (s).cvar_cl_multijump
+       #define PHYS_MULTIJUMP_CLIENT(s)        CS(s).cvar_cl_multijump
+#endif
+
+MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
+{
+    entity player = M_ARGV(0, entity);
+
+#ifdef CSQC
+       player.multijump_count = PHYS_MULTIJUMP_COUNT(player);
 #endif
+       if(!PHYS_MULTIJUMP(player)) { return; }
+
+       if(IS_ONGROUND(player))
+               player.multijump_count = 0;
+}
 
-bool PM_multijump_checkjump(entity this)
+MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
 {
-       if(!PHYS_MULTIJUMP) { return false; }
+       entity player = M_ARGV(0, entity);
 
-       int client_multijump = PHYS_MULTIJUMP_CLIENT(this);
+       if(!PHYS_MULTIJUMP(player)) { return; }
+
+       int client_multijump = PHYS_MULTIJUMP_CLIENT(player);
        if(client_multijump > 1)
-               return false; // nope
+               return; // nope
 
-       if (!IS_JUMP_HELD(this) && !IS_ONGROUND(this) && client_multijump) // jump button pressed this frame and we are in midair
-               this.multijump_ready = true;  // this is necessary to check that we released the jump button and pressed it again
+       if (!IS_JUMP_HELD(player) && !IS_ONGROUND(player) && client_multijump) // jump button pressed this frame and we are in midair
+               player.multijump_ready = true;  // this is necessary to check that we released the jump button and pressed it again
        else
-               this.multijump_ready = false;
+               player.multijump_ready = false;
 
-       int phys_multijump = PHYS_MULTIJUMP;
+       int phys_multijump = PHYS_MULTIJUMP(player);
 
-       if(!player_multijump && this.multijump_ready && (PHYS_MULTIJUMP_COUNT(this) < phys_multijump || phys_multijump == -1) && this.velocity_z > PHYS_MULTIJUMP_SPEED && (!PHYS_MULTIJUMP_MAXSPEED || vlen(this.velocity) <= PHYS_MULTIJUMP_MAXSPEED))
+       if(!M_ARGV(2, bool) && player.multijump_ready && (PHYS_MULTIJUMP_COUNT(player) < phys_multijump || phys_multijump == -1) && player.velocity_z > PHYS_MULTIJUMP_SPEED(player) &&
+               (!PHYS_MULTIJUMP_MAXSPEED(player) || vdist(player.velocity, <=, PHYS_MULTIJUMP_MAXSPEED(player))))
        {
-               if (PHYS_MULTIJUMP)
+               if (PHYS_MULTIJUMP(player))
                {
-                       if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
+                       if (!PHYS_MULTIJUMP_ADD(player)) // in this case we make the z velocity == jumpvelocity
                        {
-                               if (this.velocity_z < PHYS_JUMPVELOCITY(this))
+                               if (player.velocity_z < PHYS_JUMPVELOCITY(player))
                                {
-                                       player_multijump = true;
-                                       this.velocity_z = 0;
+                                       M_ARGV(2, bool) = true;
+                                       player.velocity_z = 0;
                                }
                        }
                        else
-                               player_multijump = true;
+                               M_ARGV(2, bool) = true;
 
-                       if(player_multijump)
+                       if(M_ARGV(2, bool))
                        {
-                               if(PHYS_MULTIJUMP_DODGING)
-                               if(this.movement_x != 0 || this.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
+                               if(PHYS_MULTIJUMP_DODGING(player))
+                               if(PHYS_CS(player).movement_x != 0 || PHYS_CS(player).movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
                                {
                                        float curspeed;
                                        vector wishvel, wishdir;
 
 /*#ifdef SVQC
                                        curspeed = max(
-                                               vlen(vec2(this.velocity)), // current xy speed
-                                               vlen(vec2(antilag_takebackavgvelocity(this, max(this.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
+                                               vlen(vec2(player.velocity)), // current xy speed
+                                               vlen(vec2(antilag_takebackavgvelocity(player, max(player.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
                                        );
 #elif defined(CSQC)*/
-                                       curspeed = vlen(vec2(this.velocity));
+                                       curspeed = vlen(vec2(player.velocity));
 //#endif
 
-                                       makevectors(this.v_angle_y * '0 1 0');
-                                       wishvel = v_forward * this.movement_x + v_right * this.movement_y;
+                                       makevectors(player.v_angle_y * '0 1 0');
+                                       wishvel = v_forward * PHYS_CS(player).movement_x + v_right * PHYS_CS(player).movement_y;
                                        wishdir = normalize(wishvel);
 
-                                       this.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
-                                       this.velocity_y = wishdir_y * curspeed;
+                                       player.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
+                                       player.velocity_y = wishdir_y * curspeed;
                                        // keep velocity_z unchanged!
                                }
-                               if (PHYS_MULTIJUMP > 0)
+                               if (PHYS_MULTIJUMP(player) > 0)
                                {
-                                       this.multijump_count += 1;
+                                       player.multijump_count += 1;
                                }
                        }
                }
-               this.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
+               player.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
        }
-
-       return false;
 }
 
-MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
-{
-#ifdef CSQC
-       self.multijump_count = PHYS_MULTIJUMP_COUNT(self);
-#endif
-       if(!PHYS_MULTIJUMP) { return; }
-
-       if(IS_ONGROUND(self))
-               self.multijump_count = 0;
-       return false;
-}
-
-MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
-{
-       return PM_multijump_checkjump(self);
-}
+REPLICATE(cvar_cl_multijump, bool, "cl_multijump");
 
 #ifdef SVQC
 
-REPLICATE(cvar_cl_multijump, bool, "cl_multijump");
-
 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString)
 {
-       ret_string = strcat(ret_string, ":multijump");
-       return false;
+       M_ARGV(0, string) = strcat(M_ARGV(0, string), ":multijump");
 }
 
 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString)
 {
-       ret_string = strcat(ret_string, ", Multi jump");
-       return false;
+       M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Multi jump");
 }
 
 #endif
+
 #endif