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