3 #include "../../../../server/antilag.qh"
5 #include "../../../physics.qh"
9 REGISTER_MUTATOR(multijump, cvar("g_multijump"))
13 addstat(STAT_MULTIJUMP_COUNT.m_id, AS_INT, multijump_count);
17 REGISTER_MUTATOR(multijump, true);
20 #define PHYS_MULTIJUMP STAT(MULTIJUMP, self)
21 #define PHYS_MULTIJUMP_SPEED STAT(MULTIJUMP_SPEED, self)
22 #define PHYS_MULTIJUMP_ADD STAT(MULTIJUMP_ADD, self)
23 #define PHYS_MULTIJUMP_MAXSPEED STAT(MULTIJUMP_MAXSPEED, self)
24 #define PHYS_MULTIJUMP_DODGING STAT(MULTIJUMP_DODGING, self)
25 #define PHYS_MULTIJUMP_COUNT(s) STAT(MULTIJUMP_COUNT, s)
27 .bool multijump_ready;
30 bool autocvar_cl_multijump = false;
32 #define PHYS_MULTIJUMP_CLIENT(s) autocvar_cl_multijump
34 .bool cvar_cl_multijump;
36 #define PHYS_MULTIJUMP_CLIENT(s) (s).cvar_cl_multijump
39 bool PM_multijump_checkjump(entity this)
41 if(!PHYS_MULTIJUMP) { return false; }
43 int client_multijump = PHYS_MULTIJUMP_CLIENT(this);
44 if(client_multijump > 1)
47 if (!IS_JUMP_HELD(this) && !IS_ONGROUND(this) && client_multijump) // jump button pressed this frame and we are in midair
48 this.multijump_ready = true; // this is necessary to check that we released the jump button and pressed it again
50 this.multijump_ready = false;
52 int phys_multijump = PHYS_MULTIJUMP;
54 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))
58 if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
60 if (this.velocity_z < PHYS_JUMPVELOCITY(this))
62 player_multijump = true;
67 player_multijump = true;
71 if(PHYS_MULTIJUMP_DODGING)
72 if(this.movement_x != 0 || this.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
75 vector wishvel, wishdir;
79 vlen(vec2(this.velocity)), // current xy speed
80 vlen(vec2(antilag_takebackavgvelocity(this, max(this.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
83 curspeed = vlen(vec2(this.velocity));
86 makevectors(this.v_angle_y * '0 1 0');
87 wishvel = v_forward * this.movement_x + v_right * this.movement_y;
88 wishdir = normalize(wishvel);
90 this.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
91 this.velocity_y = wishdir_y * curspeed;
92 // keep velocity_z unchanged!
94 if (PHYS_MULTIJUMP > 0)
96 this.multijump_count += 1;
100 this.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
106 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
109 self.multijump_count = PHYS_MULTIJUMP_COUNT(self);
111 if(!PHYS_MULTIJUMP) { return; }
113 if(IS_ONGROUND(self))
114 self.multijump_count = 0;
118 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
120 return PM_multijump_checkjump(self);
125 MUTATOR_HOOKFUNCTION(multijump, GetCvars)
127 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_multijump, "cl_multijump");
131 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString)
133 ret_string = strcat(ret_string, ":multijump");
137 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString)
139 ret_string = strcat(ret_string, ", Multi jump");