3 #include "../../../../server/antilag.qh"
5 #include "../../../physics.qh"
9 void multijump_AddStats();
11 REGISTER_MUTATOR(multijump, cvar("g_multijump"))
20 REGISTER_MUTATOR(multijump, true);
24 .bool multijump_ready;
25 .bool cvar_cl_multijump;
29 #define PHYS_MULTIJUMP getstati(STAT_MULTIJUMP)
30 #define PHYS_MULTIJUMP_SPEED getstatf(STAT_MULTIJUMP_SPEED)
31 #define PHYS_MULTIJUMP_ADD getstati(STAT_MULTIJUMP_ADD)
32 #define PHYS_MULTIJUMP_MAXSPEED getstatf(STAT_MULTIJUMP_MAXSPEED)
33 #define PHYS_MULTIJUMP_DODGING getstati(STAT_MULTIJUMP_DODGING)
37 int autocvar_g_multijump;
38 float autocvar_g_multijump_add;
39 float autocvar_g_multijump_speed;
40 float autocvar_g_multijump_maxspeed;
41 float autocvar_g_multijump_dodging = 1;
43 #define PHYS_MULTIJUMP autocvar_g_multijump
44 #define PHYS_MULTIJUMP_SPEED autocvar_g_multijump_speed
45 #define PHYS_MULTIJUMP_ADD autocvar_g_multijump_add
46 #define PHYS_MULTIJUMP_MAXSPEED autocvar_g_multijump_maxspeed
47 #define PHYS_MULTIJUMP_DODGING autocvar_g_multijump_dodging
49 .float stat_multijump;
50 .float stat_multijump_speed;
51 .float stat_multijump_add;
52 .float stat_multijump_maxspeed;
53 .float stat_multijump_dodging;
55 void multijump_UpdateStats(entity this)
57 this.stat_multijump = PHYS_MULTIJUMP;
58 this.stat_multijump_speed = PHYS_MULTIJUMP_SPEED;
59 this.stat_multijump_add = PHYS_MULTIJUMP_ADD;
60 this.stat_multijump_maxspeed = PHYS_MULTIJUMP_MAXSPEED;
61 this.stat_multijump_dodging = PHYS_MULTIJUMP_DODGING;
64 void multijump_AddStats()
66 addstat(STAT_MULTIJUMP, AS_INT, stat_multijump);
67 addstat(STAT_MULTIJUMP_SPEED, AS_FLOAT, stat_multijump_speed);
68 addstat(STAT_MULTIJUMP_ADD, AS_INT, stat_multijump_add);
69 addstat(STAT_MULTIJUMP_MAXSPEED, AS_FLOAT, stat_multijump_maxspeed);
70 addstat(STAT_MULTIJUMP_DODGING, AS_INT, stat_multijump_dodging);
75 void PM_multijump(entity this)
77 if(!PHYS_MULTIJUMP) { return; }
80 this.multijump_count = 0;
83 bool PM_multijump_checkjump(entity this)
85 if(!PHYS_MULTIJUMP) { return false; }
88 bool client_multijump = this.cvar_cl_multijump;
90 bool client_multijump = cvar("cl_multijump");
92 if(cvar("cl_multijump") > 1)
96 if (!IS_JUMP_HELD(this) && !IS_ONGROUND(this) && client_multijump) // jump button pressed this frame and we are in midair
97 this.multijump_ready = true; // this is necessary to check that we released the jump button and pressed it again
99 this.multijump_ready = false;
101 int phys_multijump = PHYS_MULTIJUMP;
104 phys_multijump = (PHYS_MULTIJUMP) ? -1 : 0;
107 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))
111 if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
113 if (this.velocity_z < PHYS_JUMPVELOCITY)
115 player_multijump = true;
120 player_multijump = true;
124 if(PHYS_MULTIJUMP_DODGING)
125 if(this.movement_x != 0 || this.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
128 vector wishvel, wishdir;
132 vlen(vec2(this.velocity)), // current xy speed
133 vlen(vec2(antilag_takebackavgvelocity(this, max(this.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
135 #elif defined(CSQC)*/
136 curspeed = vlen(vec2(this.velocity));
139 makevectors(this.v_angle_y * '0 1 0');
140 wishvel = v_forward * this.movement_x + v_right * this.movement_y;
141 wishdir = normalize(wishvel);
143 this.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
144 this.velocity_y = wishdir_y * curspeed;
145 // keep velocity_z unchanged!
147 if (PHYS_MULTIJUMP > 0)
149 this.multijump_count += 1;
153 this.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
159 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
162 multijump_UpdateStats(self);
168 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
170 return PM_multijump_checkjump(self);
175 MUTATOR_HOOKFUNCTION(multijump, GetCvars)
177 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_multijump, "cl_multijump");
181 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString)
183 ret_string = strcat(ret_string, ":multijump");
187 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString)
189 ret_string = strcat(ret_string, ", Multi jump");