3 #include <server/antilag.qh>
5 #include <common/physics/player.qh>
9 REGISTER_MUTATOR(multijump, cvar("g_multijump"));
11 REGISTER_MUTATOR(multijump, true);
14 #define PHYS_MULTIJUMP STAT(MULTIJUMP, self)
15 #define PHYS_MULTIJUMP_SPEED STAT(MULTIJUMP_SPEED, self)
16 #define PHYS_MULTIJUMP_ADD STAT(MULTIJUMP_ADD, self)
17 #define PHYS_MULTIJUMP_MAXSPEED STAT(MULTIJUMP_MAXSPEED, self)
18 #define PHYS_MULTIJUMP_DODGING STAT(MULTIJUMP_DODGING, self)
19 #define PHYS_MULTIJUMP_COUNT(s) STAT(MULTIJUMP_COUNT, s)
21 .bool multijump_ready;
24 bool autocvar_cl_multijump = false;
26 #define PHYS_MULTIJUMP_CLIENT(s) autocvar_cl_multijump
28 .bool cvar_cl_multijump;
30 #define PHYS_MULTIJUMP_CLIENT(s) (s).cvar_cl_multijump
33 bool PM_multijump_checkjump(entity this)
35 if(!PHYS_MULTIJUMP) { return false; }
37 int client_multijump = PHYS_MULTIJUMP_CLIENT(this);
38 if(client_multijump > 1)
41 if (!IS_JUMP_HELD(this) && !IS_ONGROUND(this) && client_multijump) // jump button pressed this frame and we are in midair
42 this.multijump_ready = true; // this is necessary to check that we released the jump button and pressed it again
44 this.multijump_ready = false;
46 int phys_multijump = PHYS_MULTIJUMP;
48 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))
52 if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
54 if (this.velocity_z < PHYS_JUMPVELOCITY(this))
56 player_multijump = true;
61 player_multijump = true;
65 if(PHYS_MULTIJUMP_DODGING)
66 if(this.movement_x != 0 || this.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
69 vector wishvel, wishdir;
73 vlen(vec2(this.velocity)), // current xy speed
74 vlen(vec2(antilag_takebackavgvelocity(this, max(this.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
77 curspeed = vlen(vec2(this.velocity));
80 makevectors(this.v_angle_y * '0 1 0');
81 wishvel = v_forward * this.movement_x + v_right * this.movement_y;
82 wishdir = normalize(wishvel);
84 this.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
85 this.velocity_y = wishdir_y * curspeed;
86 // keep velocity_z unchanged!
88 if (PHYS_MULTIJUMP > 0)
90 this.multijump_count += 1;
94 this.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
100 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
103 self.multijump_count = PHYS_MULTIJUMP_COUNT(self);
105 if(!PHYS_MULTIJUMP) { return; }
107 if(IS_ONGROUND(self))
108 self.multijump_count = 0;
112 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
114 return PM_multijump_checkjump(self);
119 REPLICATE(cvar_cl_multijump, bool, "cl_multijump");
121 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString)
123 ret_string = strcat(ret_string, ":multijump");
127 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString)
129 ret_string = strcat(ret_string, ", Multi jump");