]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_multijump.qc
Start of uncrusticracy script, and kill trailing whitespace in all sources.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_multijump.qc
1 .float multijump_count;
2 .float multijump_ready;
3
4 MUTATOR_HOOKFUNCTION(multijump_PlayerPhysics)
5 {
6         if(self.flags & FL_ONGROUND)
7         {
8                 if (autocvar_g_multijump > 0)
9                         self.multijump_count = 0;
10                 else
11                         self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
12         }
13
14         return FALSE;
15 }
16
17 MUTATOR_HOOKFUNCTION(multijump_PlayerJump)
18 {
19         if (self.flags & FL_JUMPRELEASED && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
20                 self.multijump_ready = TRUE;  // this is necessary to check that we released the jump button and pressed it again
21         else
22                 self.multijump_ready = FALSE;
23
24         if(!player_multijump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed)
25         {
26                 if (autocvar_g_multijump)
27                 {
28                         if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
29                         {
30                                 if (self.velocity_z < autocvar_sv_jumpvelocity)
31                                 {
32                                         player_multijump = TRUE;
33                                         self.velocity_z = 0;
34                                 }
35                         }
36                         else
37                                 player_multijump = TRUE;
38
39                         if(player_multijump)
40                         {
41                                 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
42                                 {
43                                         float curspeed;
44                                         vector wishvel, wishdir;
45
46                                         curspeed = max(
47                                                 vlen(vec2(self.velocity)), // current xy speed
48                                                 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
49                                         );
50                                         makevectors(self.v_angle_y * '0 1 0');
51                                         wishvel = v_forward * self.movement_x + v_right * self.movement_y;
52                                         wishdir = normalize(wishvel);
53
54                                         self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
55                                         self.velocity_y = wishdir_y * curspeed;
56                                         // keep velocity_z unchanged!
57                                 }
58                                 if (autocvar_g_multijump > 0)
59                                         self.multijump_count += 1;
60                         }
61                 }
62                 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
63         }
64
65         return FALSE;
66 }
67
68 MUTATOR_HOOKFUNCTION(multijump_BuildMutatorsString)
69 {
70         ret_string = strcat(ret_string, ":multijump");
71         return FALSE;
72 }
73
74 MUTATOR_HOOKFUNCTION(multijump_BuildMutatorsPrettyString)
75 {
76         ret_string = strcat(ret_string, ", Multi jump");
77         return FALSE;
78 }
79
80 MUTATOR_DEFINITION(mutator_multijump)
81 {
82         MUTATOR_HOOK(PlayerPhysics, multijump_PlayerPhysics, CBC_ORDER_ANY);
83         MUTATOR_HOOK(PlayerJump, multijump_PlayerJump, CBC_ORDER_ANY);
84         MUTATOR_HOOK(BuildMutatorsString, multijump_BuildMutatorsString, CBC_ORDER_ANY);
85         MUTATOR_HOOK(BuildMutatorsPrettyString, multijump_BuildMutatorsPrettyString, CBC_ORDER_ANY);
86
87         return FALSE;
88 }