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(s) STAT(MULTIJUMP, s)
15 #define PHYS_MULTIJUMP_SPEED(s) STAT(MULTIJUMP_SPEED, s)
16 #define PHYS_MULTIJUMP_ADD(s) STAT(MULTIJUMP_ADD, s)
17 #define PHYS_MULTIJUMP_MAXSPEED(s) STAT(MULTIJUMP_MAXSPEED, s)
18 #define PHYS_MULTIJUMP_DODGING(s) STAT(MULTIJUMP_DODGING, s)
19 #define PHYS_MULTIJUMP_COUNT(s) STAT(MULTIJUMP_COUNT, s)
21 .bool multijump_ready;
24 bool autocvar_cl_multijump = true;
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 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
35 entity player = M_ARGV(0, entity);
38 player.multijump_count = PHYS_MULTIJUMP_COUNT(player);
40 if(!PHYS_MULTIJUMP(player)) { return; }
42 if(IS_ONGROUND(player))
43 player.multijump_count = 0;
46 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
48 entity player = M_ARGV(0, entity);
50 if(!PHYS_MULTIJUMP(player)) { return; }
52 int client_multijump = PHYS_MULTIJUMP_CLIENT(player);
53 if(client_multijump > 1)
56 if (!IS_JUMP_HELD(player) && !IS_ONGROUND(player) && client_multijump) // jump button pressed this frame and we are in midair
57 player.multijump_ready = true; // this is necessary to check that we released the jump button and pressed it again
59 player.multijump_ready = false;
61 int phys_multijump = PHYS_MULTIJUMP(player);
63 if(!M_ARGV(2, bool) && player.multijump_ready && (PHYS_MULTIJUMP_COUNT(player) < phys_multijump || phys_multijump == -1) && player.velocity_z > PHYS_MULTIJUMP_SPEED(player) &&
64 (!PHYS_MULTIJUMP_MAXSPEED(player) || vdist(player.velocity, <=, PHYS_MULTIJUMP_MAXSPEED(player))))
66 if (PHYS_MULTIJUMP(player))
68 if (!PHYS_MULTIJUMP_ADD(player)) // in this case we make the z velocity == jumpvelocity
70 if (player.velocity_z < PHYS_JUMPVELOCITY(player))
72 M_ARGV(2, bool) = true;
73 player.velocity_z = 0;
77 M_ARGV(2, bool) = true;
81 if(PHYS_MULTIJUMP_DODGING(player))
82 if(player.movement_x != 0 || player.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
85 vector wishvel, wishdir;
89 vlen(vec2(player.velocity)), // current xy speed
90 vlen(vec2(antilag_takebackavgvelocity(player, max(player.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
93 curspeed = vlen(vec2(player.velocity));
96 makevectors(player.v_angle_y * '0 1 0');
97 wishvel = v_forward * player.movement_x + v_right * player.movement_y;
98 wishdir = normalize(wishvel);
100 player.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
101 player.velocity_y = wishdir_y * curspeed;
102 // keep velocity_z unchanged!
104 if (PHYS_MULTIJUMP(player) > 0)
106 player.multijump_count += 1;
110 player.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
116 REPLICATE(cvar_cl_multijump, bool, "cl_multijump");
118 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString)
120 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":multijump");
123 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString)
125 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Multi jump");