]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/physics/movetypes/toss.qc
5bea38c5b806d97f49594f911be68d64636ceeda
[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         if (this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS)
36         {
37                 this.move_didgravity = true;
38                 this.move_velocity_z -= (((this.gravity) ? this.gravity : 1) * PHYS_GRAVITY(this) * dt);
39         }
40
41         this.move_angles = this.move_angles + this.move_avelocity * dt;
42
43         float movetime = dt;
44         for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; ++bump)
45         {
46                 vector move = this.move_velocity * movetime;
47                 _Movetype_PushEntity(this, move, true);
48                 if (wasfreed(this))
49                         return;
50
51                 if (trace_startsolid)
52                 {
53                         _Movetype_UnstickEntity(this);
54                         _Movetype_PushEntity(this, move, false);
55                         if (wasfreed(this))
56                                 return;
57                 }
58
59                 if (trace_fraction == 1)
60                         break;
61
62                 movetime *= 1 - min(1, trace_fraction);
63
64                 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
65                 {
66                         this.move_velocity = _Movetype_ClipVelocity(this.move_velocity, trace_plane_normal, 2.0);
67                         this.move_flags &= ~FL_ONGROUND;
68                 }
69                 else if (this.move_movetype == MOVETYPE_BOUNCE)
70                 {
71                         float bouncefac = this.move_bounce_factor;     if (!bouncefac)  bouncefac = 0.5;
72                         float bouncestop = this.move_bounce_stopspeed; if (!bouncestop) bouncestop = 60 / 800;
73                         bouncestop *= (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
74
75                         this.move_velocity = _Movetype_ClipVelocity(this.move_velocity, trace_plane_normal, 1 + bouncefac);
76
77                         float d = trace_plane_normal * this.move_velocity;
78                         if (trace_plane_normal.z > 0.7 && d < bouncestop && d > -bouncestop)
79                         {
80                                 this.move_flags |= FL_ONGROUND;
81                                 this.move_groundentity = trace_ent;
82                                 this.move_velocity = '0 0 0';
83                                 this.move_avelocity = '0 0 0';
84                         }
85                         else
86                         {
87                                 this.move_flags &= ~FL_ONGROUND;
88                         }
89                 }
90                 else
91                 {
92                         this.move_velocity = _Movetype_ClipVelocity(this.move_velocity, trace_plane_normal, 1.0);
93                         if (trace_plane_normal.z > 0.7)
94                         {
95                                 this.move_flags |= FL_ONGROUND;
96                                 this.move_groundentity = trace_ent;
97                                 if (trace_ent.solid == SOLID_BSP)
98                                         this.move_suspendedinair = true;
99                                 this.move_velocity = '0 0 0';
100                                 this.move_avelocity = '0 0 0';
101                         }
102                         else
103                         {
104                                 this.move_flags &= ~FL_ONGROUND;
105                         }
106                 }
107
108                 // DP revision 8905 (just, WHY...)
109                 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
110                         break;
111
112                 // DP revision 8918 (WHY...)
113                 if (this.move_flags & FL_ONGROUND)
114                         break;
115         }
116
117         //if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE && this.move_didgravity > 0 && !(this.move_flags & FL_ONGROUND))
118         //      this.move_velocity_z -= 0.5 * dt * (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
119
120         _Movetype_CheckWaterTransition(this);
121 }