]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/multijump/multijump.qc
Merge branch 'master' into TimePath/stats
[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 .int multijump_count;
8 .bool multijump_ready;
9 .bool cvar_cl_multijump;
10
11 #define PHYS_MULTIJUMP                          STAT(MULTIJUMP, self)
12 #define PHYS_MULTIJUMP_SPEED            STAT(MULTIJUMP_SPEED, self)
13 #define PHYS_MULTIJUMP_ADD                      STAT(MULTIJUMP_ADD, self)
14 #define PHYS_MULTIJUMP_MAXSPEED         STAT(MULTIJUMP_MAXSPEED, self)
15 #define PHYS_MULTIJUMP_DODGING          STAT(MULTIJUMP_DODGING, self)
16
17 void PM_multijump()
18 {SELFPARAM();
19         if(!PHYS_MULTIJUMP) { return; }
20
21         if(IS_ONGROUND(self))
22         {
23                 self.multijump_count = 0;
24         }
25 }
26
27 bool PM_multijump_checkjump()
28 {SELFPARAM();
29         if(!PHYS_MULTIJUMP) { return false; }
30
31 #ifdef SVQC
32         bool client_multijump = self.cvar_cl_multijump;
33 #elif defined(CSQC)
34         bool client_multijump = cvar("cl_multijump");
35
36         if(cvar("cl_multijump") > 1)
37                 return false; // nope
38 #endif
39
40         if (!IS_JUMP_HELD(self) && !IS_ONGROUND(self) && client_multijump) // jump button pressed this frame and we are in midair
41                 self.multijump_ready = true;  // this is necessary to check that we released the jump button and pressed it again
42         else
43                 self.multijump_ready = false;
44
45         int phys_multijump = PHYS_MULTIJUMP;
46
47 #ifdef CSQC
48         phys_multijump = (PHYS_MULTIJUMP) ? -1 : 0;
49 #endif
50
51         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))
52         {
53                 if (PHYS_MULTIJUMP)
54                 {
55                         if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
56                         {
57                                 if (self.velocity_z < PHYS_JUMPVELOCITY)
58                                 {
59                                         player_multijump = true;
60                                         self.velocity_z = 0;
61                                 }
62                         }
63                         else
64                                 player_multijump = true;
65
66                         if(player_multijump)
67                         {
68                                 if(PHYS_MULTIJUMP_DODGING)
69                                 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
70                                 {
71                                         float curspeed;
72                                         vector wishvel, wishdir;
73
74 /*#ifdef SVQC
75                                         curspeed = max(
76                                                 vlen(vec2(self.velocity)), // current xy speed
77                                                 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
78                                         );
79 #elif defined(CSQC)*/
80                                         curspeed = vlen(vec2(self.velocity));
81 //#endif
82
83                                         makevectors(self.v_angle_y * '0 1 0');
84                                         wishvel = v_forward * self.movement_x + v_right * self.movement_y;
85                                         wishdir = normalize(wishvel);
86
87                                         self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
88                                         self.velocity_y = wishdir_y * curspeed;
89                                         // keep velocity_z unchanged!
90                                 }
91                                 if (PHYS_MULTIJUMP > 0)
92                                 {
93                                         self.multijump_count += 1;
94                                 }
95                         }
96                 }
97                 self.multijump_ready = false; // require releasing and pressing the jump button again for the next jump
98         }
99
100         return false;
101 }
102
103 #ifdef SVQC
104 REGISTER_MUTATOR(multijump, cvar("g_multijump"));
105
106 MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics)
107 {
108         PM_multijump();
109
110         return false;
111 }
112
113 MUTATOR_HOOKFUNCTION(multijump, PlayerJump)
114 {
115         return PM_multijump_checkjump();
116 }
117
118 MUTATOR_HOOKFUNCTION(multijump, GetCvars)
119 {
120         GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_multijump, "cl_multijump");
121         return false;
122 }
123
124 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString)
125 {
126         ret_string = strcat(ret_string, ":multijump");
127         return false;
128 }
129
130 MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString)
131 {
132         ret_string = strcat(ret_string, ", Multi jump");
133         return false;
134 }
135
136 #endif
137 #endif