]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/walljump/walljump.qc
Merge branch 'terencehill/campaign_balance_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / walljump / walljump.qc
1 #include "walljump.qh"
2
3 #ifdef GAMEQC
4 #ifdef CSQC
5 REGISTER_MUTATOR(walljump, true);
6 #elif defined(SVQC)
7 REGISTER_MUTATOR(walljump, autocvar_g_walljump);
8 #endif
9
10 #define PHYS_WALLJUMP(s)                                                STAT(WALLJUMP, s)
11 #define PHYS_WALLJUMP_VELOCITY_Z_FACTOR(s)              STAT(WALLJUMP_VELOCITY_Z_FACTOR, s)
12 #define PHYS_WALLJUMP_VELOCITY_XY_FACTOR(s)     STAT(WALLJUMP_VELOCITY_XY_FACTOR, s)
13 #define PHYS_WALLJUMP_DELAY(s)                                  STAT(WALLJUMP_DELAY, s)
14 #define PHYS_WALLJUMP_FORCE(s)                                  STAT(WALLJUMP_FORCE, s)
15
16 vector PlayerTouchWall(entity this)
17 {
18 #define TRACE(newvec) \
19         tracebox (start, this.mins, this.maxs, (newvec), true, this); \
20         if (trace_fraction < 1 && vdist(this.origin - trace_endpos, <, dist) && trace_plane_normal_z < max_normal) \
21         if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)) \
22                 return trace_plane_normal;
23
24         vector forward, right, up;
25         MAKE_VECTORS(this.angles, forward, right, up);
26
27         float dist = 10, max_normal = 0.2, scaler = 100;
28         vector start = this.origin;
29         TRACE(start + forward * scaler)
30         TRACE(start - forward * scaler)
31         TRACE(start + right * scaler)
32         TRACE(start - right * scaler)
33 #undef TRACE
34         return '0 0 0';
35 }
36
37 MUTATOR_HOOKFUNCTION(walljump, PlayerJump)
38 {
39         entity player = M_ARGV(0, entity);
40
41         if(PHYS_WALLJUMP(player))
42         if(time - STAT(LASTWJ, player) > PHYS_WALLJUMP_DELAY(player)) // can't do this on client, as it's too stupid to obey counters
43         if(!IS_ONGROUND(player))
44         if(player.move_movetype != MOVETYPE_NONE && player.move_movetype != MOVETYPE_FOLLOW && player.move_movetype != MOVETYPE_FLY && player.move_movetype != MOVETYPE_NOCLIP)
45         if(!IS_JUMP_HELD(player))
46         if(!STAT(FROZEN, player))
47         if(!IS_DEAD(player))
48         {
49                 vector plane_normal = PlayerTouchWall(player);
50
51                 if(plane_normal != '0 0 0')
52                 {
53                         float wj_force = PHYS_WALLJUMP_FORCE(player);
54                         float wj_xy_factor = PHYS_WALLJUMP_VELOCITY_XY_FACTOR(player);
55                         float wj_z_factor = PHYS_WALLJUMP_VELOCITY_Z_FACTOR(player);
56                         player.velocity_x += plane_normal_x * wj_force;
57                         player.velocity_x /= wj_xy_factor;
58                         player.velocity_y += plane_normal_y * wj_force;
59                         player.velocity_y /= wj_xy_factor;
60                         player.velocity_z = PHYS_JUMPVELOCITY(player) * wj_z_factor;
61                         if(PHYS_INPUT_BUTTON_CROUCH(player)) player.velocity_z *= -1;
62
63 #ifdef SVQC
64                         STAT(LASTWJ, player) = time;
65                         player.oldvelocity = player.velocity;
66                         Send_Effect(EFFECT_SMOKE_RING, trace_endpos, plane_normal, 5);
67                         PlayerSound(player, playersound_jump, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
68                         animdecide_setaction(player, ANIMACTION_JUMP, true);
69 #endif
70
71                         M_ARGV(2, bool) = true; // multijump
72                 }
73         }
74 }
75
76 #endif