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