]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/physics/movetypes/toss.qc
Merge branch 'master' into Mario/balance
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics / movetypes / toss.qc
1 #include "../player.qh"
2
3 void _Movetype_Physics_Toss(entity this, float dt)  // SV_Physics_Toss
4 {
5         if (this.move_flags & FL_ONGROUND)
6         {
7                 if (this.move_velocity.z >= 1 / 32 && UPWARD_VELOCITY_CLEARS_ONGROUND(this))
8                 {
9                         this.move_flags &= ~FL_ONGROUND;
10                 }
11                 else if (!this.move_groundentity)
12                 {
13                         return;
14                 }
15                 else if (this.move_suspendedinair && wasfreed(this.move_groundentity))
16                 {
17                         this.move_groundentity = NULL;
18                         return;
19                 }
20         }
21
22         this.move_suspendedinair = false;
23
24         _Movetype_CheckVelocity(this);
25
26         if (this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS)
27         {
28                 this.move_didgravity = 1;
29                 this.move_velocity_z -= (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1)
30                     * dt
31                     * (this.gravity ? this.gravity : 1)
32                     * PHYS_GRAVITY(this);
33         }
34
35         this.move_angles = this.move_angles + this.move_avelocity * dt;
36
37         float movetime = dt;
38         for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; ++bump)
39         {
40                 vector move = this.move_velocity * movetime;
41                 _Movetype_PushEntity(this, move, true);
42                 if (wasfreed(this))
43                         return;
44
45                 if (trace_startsolid)
46                 {
47                         _Movetype_UnstickEntity(this);
48                         _Movetype_PushEntity(this, move, false);
49                         if (wasfreed(this))
50                                 return;
51                 }
52
53                 if (trace_fraction == 1)
54                         break;
55
56                 movetime *= 1 - min(1, trace_fraction);
57
58                 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
59                 {
60                         this.move_velocity = _Movetype_ClipVelocity(this.move_velocity, trace_plane_normal, 2.0);
61                         this.move_flags &= ~FL_ONGROUND;
62                 }
63                 else if (this.move_movetype == MOVETYPE_BOUNCE)
64                 {
65                         float bouncefac = this.move_bounce_factor;     if (!bouncefac)  bouncefac = 0.5;
66                         float bouncestop = this.move_bounce_stopspeed; if (!bouncestop) bouncestop = 60 / 800;
67                         bouncestop *= (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
68
69                         this.move_velocity = _Movetype_ClipVelocity(this.move_velocity, trace_plane_normal, 1 + bouncefac);
70
71                         float d = trace_plane_normal * this.move_velocity;
72                         if (trace_plane_normal.z > 0.7 && d < bouncestop && d > -bouncestop)
73                         {
74                                 this.move_flags |= FL_ONGROUND;
75                                 this.move_groundentity = trace_ent;
76                                 this.move_velocity = '0 0 0';
77                                 this.move_avelocity = '0 0 0';
78                         }
79                         else
80                         {
81                                 this.move_flags &= ~FL_ONGROUND;
82                         }
83                 }
84                 else
85                 {
86                         this.move_velocity = _Movetype_ClipVelocity(this.move_velocity, trace_plane_normal, 1.0);
87                         if (trace_plane_normal.z > 0.7)
88                         {
89                                 this.move_flags |= FL_ONGROUND;
90                                 this.move_groundentity = trace_ent;
91                                 if (trace_ent.solid == SOLID_BSP)
92                                         this.move_suspendedinair = true;
93                                 this.move_velocity = '0 0 0';
94                                 this.move_avelocity = '0 0 0';
95                         }
96                         else
97                         {
98                                 this.move_flags &= ~FL_ONGROUND;
99                         }
100                 }
101
102                 // DP revision 8905 (just, WHY...)
103                 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
104                         break;
105
106                 // DP revision 8918 (WHY...)
107                 if (this.move_flags & FL_ONGROUND)
108                         break;
109         }
110
111         if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE && this.move_didgravity > 0 && !(this.move_flags & FL_ONGROUND))
112                 this.move_velocity_z -= 0.5 * dt * (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
113
114         _Movetype_CheckWaterTransition(this);
115 }