3 #include "../../../../server/antilag.qh"
5 #include "../../../physics.qh"
9 .bool cvar_cl_multijump;
13 #define PHYS_MULTIJUMP STAT(MULTIJUMP)
14 #define PHYS_MULTIJUMP_SPEED STAT(MULTIJUMP_SPEED)
15 #define PHYS_MULTIJUMP_ADD STAT(MULTIJUMP_ADD)
16 #define PHYS_MULTIJUMP_MAXSPEED STAT(MULTIJUMP_MAXSPEED)
17 #define PHYS_MULTIJUMP_DODGING STAT(MULTIJUMP_DODGING)
21 int autocvar_g_multijump;
22 float autocvar_g_multijump_add;
23 float autocvar_g_multijump_speed;
24 float autocvar_g_multijump_maxspeed;
25 float autocvar_g_multijump_dodging = 1;
27 #define PHYS_MULTIJUMP autocvar_g_multijump
28 #define PHYS_MULTIJUMP_SPEED autocvar_g_multijump_speed
29 #define PHYS_MULTIJUMP_ADD autocvar_g_multijump_add
30 #define PHYS_MULTIJUMP_MAXSPEED autocvar_g_multijump_maxspeed
31 #define PHYS_MULTIJUMP_DODGING autocvar_g_multijump_dodging
33 .float stat_multijump = _STAT(MULTIJUMP);
34 .float stat_multijump_speed = _STAT(MULTIJUMP_SPEED);
35 .float stat_multijump_add = _STAT(MULTIJUMP_ADD);
36 .float stat_multijump_maxspeed = _STAT(MULTIJUMP_MAXSPEED);
37 .float stat_multijump_dodging = _STAT(MULTIJUMP_DODGING);
39 void multijump_UpdateStats()
41 STAT(MULTIJUMP, this) = PHYS_MULTIJUMP;
42 STAT(MULTIJUMP_SPEED, this) = PHYS_MULTIJUMP_SPEED;
43 STAT(MULTIJUMP_ADD, this) = PHYS_MULTIJUMP_ADD;
44 STAT(MULTIJUMP_MAXSPEED, this) = PHYS_MULTIJUMP_MAXSPEED;
45 STAT(MULTIJUMP_DODGING, this) = PHYS_MULTIJUMP_DODGING;
52 if(!PHYS_MULTIJUMP) { return; }
56 self.multijump_count = 0;
60 bool PM_multijump_checkjump()
62 if(!PHYS_MULTIJUMP) { return false; }
65 bool client_multijump = self.cvar_cl_multijump;
67 bool client_multijump = cvar("cl_multijump");
69 if(cvar("cl_multijump") > 1)
73 if (!IS_JUMP_HELD(self) && !IS_ONGROUND(self) && client_multijump) // jump button pressed this frame and we are in midair
74 self.multijump_ready = true; // this is necessary to check that we released the jump button and pressed it again
76 self.multijump_ready = false;
78 int phys_multijump = PHYS_MULTIJUMP;
81 phys_multijump = (PHYS_MULTIJUMP) ? -1 : 0;
84 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))
88 if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
90 if (self.velocity_z < PHYS_JUMPVELOCITY)
92 player_multijump = true;
97 player_multijump = true;
101 if(PHYS_MULTIJUMP_DODGING)
102 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
105 vector wishvel, wishdir;
109 vlen(vec2(self.velocity)), // current xy speed
110 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
112 #elif defined(CSQC)*/
113 curspeed = vlen(vec2(self.velocity));
116 makevectors(self.v_angle_y * '0 1 0');
117 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
118 wishdir = normalize(wishvel);
120 self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
121 self.velocity_y = wishdir_y * curspeed;
122 // keep velocity_z unchanged!
124 if (PHYS_MULTIJUMP > 0)
126 self.multijump_count += 1;
130 self.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
137 REGISTER_MUTATOR(multijump, cvar("g_multijump"));
139 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
141 multijump_UpdateStats();
147 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
149 return PM_multijump_checkjump();
152 MUTATOR_HOOKFUNCTION(multijump, GetCvars)
154 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_multijump, "cl_multijump");
158 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString)
160 ret_string = strcat(ret_string, ":multijump");
164 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString)
166 ret_string = strcat(ret_string, ", Multi jump");