]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/multijump/multijump.qc
This commit is dedicated to TimePath
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / multijump / multijump.qc
1 #ifdef IMPLEMENTATION
2 #ifdef SVQC
3         #include "../../../../server/antilag.qh"
4 #endif
5 #include "../../../physics.qh"
6
7
8 #if defined(SVQC)
9 REGISTER_MUTATOR(multijump, cvar("g_multijump"))
10 {
11         MUTATOR_ONADD
12         {
13                 addstat(STAT_MULTIJUMP_COUNT.m_id, AS_INT, multijump_count);
14         }
15 }
16 #elif defined(CSQC)
17 REGISTER_MUTATOR(multijump, true);
18 #endif
19
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)
26
27 .bool multijump_ready;
28
29 #ifdef CSQC
30 bool autocvar_cl_multijump = false;
31
32         #define PHYS_MULTIJUMP_CLIENT(s)        autocvar_cl_multijump
33 #elif defined(SVQC)
34 .bool cvar_cl_multijump;
35
36         #define PHYS_MULTIJUMP_CLIENT(s)        (s).cvar_cl_multijump
37 #endif
38
39 bool PM_multijump_checkjump(entity this)
40 {
41         if(!PHYS_MULTIJUMP) { return false; }
42
43         int client_multijump = PHYS_MULTIJUMP_CLIENT(this);
44         if(client_multijump > 1)
45                 return false; // nope
46
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
49         else
50                 this.multijump_ready = false;
51
52         int phys_multijump = PHYS_MULTIJUMP;
53
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))
55         {
56                 if (PHYS_MULTIJUMP)
57                 {
58                         if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
59                         {
60                                 if (this.velocity_z < PHYS_JUMPVELOCITY(this))
61                                 {
62                                         player_multijump = true;
63                                         this.velocity_z = 0;
64                                 }
65                         }
66                         else
67                                 player_multijump = true;
68
69                         if(player_multijump)
70                         {
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
73                                 {
74                                         float curspeed;
75                                         vector wishvel, wishdir;
76
77 /*#ifdef SVQC
78                                         curspeed = max(
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
81                                         );
82 #elif defined(CSQC)*/
83                                         curspeed = vlen(vec2(this.velocity));
84 //#endif
85
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);
89
90                                         this.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
91                                         this.velocity_y = wishdir_y * curspeed;
92                                         // keep velocity_z unchanged!
93                                 }
94                                 if (PHYS_MULTIJUMP > 0)
95                                 {
96                                         this.multijump_count += 1;
97                                 }
98                         }
99                 }
100                 this.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
101         }
102
103         return false;
104 }
105
106 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
107 {
108 #ifdef CSQC
109         self.multijump_count = PHYS_MULTIJUMP_COUNT(self);
110 #endif
111         if(!PHYS_MULTIJUMP) { return; }
112
113         if(IS_ONGROUND(self))
114                 self.multijump_count = 0;
115         return false;
116 }
117
118 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
119 {
120         return PM_multijump_checkjump(self);
121 }
122
123 #ifdef SVQC
124
125 MUTATOR_HOOKFUNCTION(multijump, GetCvars)
126 {
127         GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_multijump, "cl_multijump");
128         return false;
129 }
130
131 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString)
132 {
133         ret_string = strcat(ret_string, ":multijump");
134         return false;
135 }
136
137 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString)
138 {
139         ret_string = strcat(ret_string, ", Multi jump");
140         return false;
141 }
142
143 #endif
144 #endif