]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/multijump/multijump.qc
Make physics hook common, move multijump stuff into multijump file
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / multijump / multijump.qc
index 00e22af7234a24cf7a915dfb1e02151bf070be50..10214591e5e62d8a796d25309b3f245df3a99616 100644 (file)
@@ -4,6 +4,22 @@
 #endif
 #include "../../../physics.qh"
 
+
+#if defined(SVQC)
+void multijump_AddStats();
+
+REGISTER_MUTATOR(multijump, cvar("g_multijump"))
+{
+       MUTATOR_ONADD
+       {
+               multijump_AddStats();
+       }
+       return false;
+}
+#elif defined(CSQC)
+REGISTER_MUTATOR(multijump, true);
+#endif
+
 .int multijump_count;
 .bool multijump_ready;
 .bool cvar_cl_multijump;
@@ -36,13 +52,13 @@ float autocvar_g_multijump_dodging = 1;
 .float stat_multijump_maxspeed;
 .float stat_multijump_dodging;
 
-void multijump_UpdateStats()
-{SELFPARAM();
-       self.stat_multijump = PHYS_MULTIJUMP;
-       self.stat_multijump_speed = PHYS_MULTIJUMP_SPEED;
-       self.stat_multijump_add = PHYS_MULTIJUMP_ADD;
-       self.stat_multijump_maxspeed = PHYS_MULTIJUMP_MAXSPEED;
-       self.stat_multijump_dodging = PHYS_MULTIJUMP_DODGING;
+void multijump_UpdateStats(entity this)
+{
+       this.stat_multijump = PHYS_MULTIJUMP;
+       this.stat_multijump_speed = PHYS_MULTIJUMP_SPEED;
+       this.stat_multijump_add = PHYS_MULTIJUMP_ADD;
+       this.stat_multijump_maxspeed = PHYS_MULTIJUMP_MAXSPEED;
+       this.stat_multijump_dodging = PHYS_MULTIJUMP_DODGING;
 }
 
 void multijump_AddStats()
@@ -56,22 +72,20 @@ void multijump_AddStats()
 
 #endif
 
-void PM_multijump()
-{SELFPARAM();
+void PM_multijump(entity this)
+{
        if(!PHYS_MULTIJUMP) { return; }
 
-       if(IS_ONGROUND(self))
-       {
-               self.multijump_count = 0;
-       }
+       if(IS_ONGROUND(this))
+               this.multijump_count = 0;
 }
 
-bool PM_multijump_checkjump()
-{SELFPARAM();
+bool PM_multijump_checkjump(entity this)
+{
        if(!PHYS_MULTIJUMP) { return false; }
 
 #ifdef SVQC
-       bool client_multijump = self.cvar_cl_multijump;
+       bool client_multijump = this.cvar_cl_multijump;
 #elif defined(CSQC)
        bool client_multijump = cvar("cl_multijump");
 
@@ -79,10 +93,10 @@ bool PM_multijump_checkjump()
                return false; // nope
 #endif
 
-       if (!IS_JUMP_HELD(self) && !IS_ONGROUND(self) && client_multijump) // 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
+       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
        else
-               self.multijump_ready = false;
+               this.multijump_ready = false;
 
        int phys_multijump = PHYS_MULTIJUMP;
 
@@ -90,16 +104,16 @@ bool PM_multijump_checkjump()
        phys_multijump = (PHYS_MULTIJUMP) ? -1 : 0;
 #endif
 
-       if(!player_multijump && self.multijump_ready && (self.multijump_count < phys_multijump || phys_multijump == -1) && self.velocity_z > PHYS_MULTIJUMP_SPEED && (!PHYS_MULTIJUMP_MAXSPEED || vlen(self.velocity) <= PHYS_MULTIJUMP_MAXSPEED))
+       if(!player_multijump && this.multijump_ready && (this.multijump_count < phys_multijump || phys_multijump == -1) && this.velocity_z > PHYS_MULTIJUMP_SPEED && (!PHYS_MULTIJUMP_MAXSPEED || vlen(this.velocity) <= PHYS_MULTIJUMP_MAXSPEED))
        {
                if (PHYS_MULTIJUMP)
                {
                        if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
                        {
-                               if (self.velocity_z < PHYS_JUMPVELOCITY)
+                               if (this.velocity_z < PHYS_JUMPVELOCITY)
                                {
                                        player_multijump = true;
-                                       self.velocity_z = 0;
+                                       this.velocity_z = 0;
                                }
                        }
                        else
@@ -108,63 +122,56 @@ bool PM_multijump_checkjump()
                        if(player_multijump)
                        {
                                if(PHYS_MULTIJUMP_DODGING)
-                               if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
+                               if(this.movement_x != 0 || this.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(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
+                                               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
                                        );
 #elif defined(CSQC)*/
-                                       curspeed = vlen(vec2(self.velocity));
+                                       curspeed = vlen(vec2(this.velocity));
 //#endif
 
-                                       makevectors(self.v_angle_y * '0 1 0');
-                                       wishvel = v_forward * self.movement_x + v_right * self.movement_y;
+                                       makevectors(this.v_angle_y * '0 1 0');
+                                       wishvel = v_forward * this.movement_x + v_right * this.movement_y;
                                        wishdir = normalize(wishvel);
 
-                                       self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
-                                       self.velocity_y = wishdir_y * curspeed;
+                                       this.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
+                                       this.velocity_y = wishdir_y * curspeed;
                                        // keep velocity_z unchanged!
                                }
                                if (PHYS_MULTIJUMP > 0)
                                {
-                                       self.multijump_count += 1;
+                                       this.multijump_count += 1;
                                }
                        }
                }
-               self.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
+               this.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
        }
 
        return false;
 }
 
-#ifdef SVQC
-REGISTER_MUTATOR(multijump, cvar("g_multijump"))
-{
-       MUTATOR_ONADD
-       {
-               multijump_AddStats();
-       }
-       return false;
-}
-
 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
 {
-       multijump_UpdateStats();
-       PM_multijump();
-
+#ifdef SVQC
+       multijump_UpdateStats(self);
+#endif
+       PM_multijump(self);
        return false;
 }
 
 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
 {
-       return PM_multijump_checkjump();
+       return PM_multijump_checkjump(self);
 }
 
+#ifdef SVQC
+
 MUTATOR_HOOKFUNCTION(multijump, GetCvars)
 {
        GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_multijump, "cl_multijump");