Remove .move_* fields and MOVETYPE_PUSH logic (doesn't work)
[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.flags & FL_ONGROUND)
6         {
7                 if (this.velocity.z >= 1 / 32 && UPWARD_VELOCITY_CLEARS_ONGROUND(this))
8                 {
9                         this.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.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.velocity_z -= (((this.gravity) ? this.gravity : 1) * PHYS_GRAVITY(this) * dt);
39         }
40
41         this.angles = this.angles + this.avelocity * dt;
42
43         float movetime = dt;
44         for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; ++bump)
45         {
46                 vector move = this.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.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 2.0);
67                         this.flags &= ~FL_ONGROUND;
68                 }
69                 else if (this.move_movetype == MOVETYPE_BOUNCE)
70                 {
71                         float bouncefac = this.bouncefactor;     if (!bouncefac)  bouncefac = 0.5;
72                         float bstop = this.bouncestop; if (!bstop) bstop = 60 / 800;
73                         bstop *= (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
74
75                         this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1 + bouncefac);
76
77                         float d = trace_plane_normal * this.velocity;
78                         if (trace_plane_normal.z > 0.7 && d < bstop && d > -bstop)
79                         {
80                                 this.flags |= FL_ONGROUND;
81                                 this.move_groundentity = trace_ent;
82                                 this.velocity = '0 0 0';
83                                 this.avelocity = '0 0 0';
84                         }
85                         else
86                         {
87                                 this.flags &= ~FL_ONGROUND;
88                         }
89                 }
90                 else
91                 {
92                         this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1.0);
93                         if (trace_plane_normal.z > 0.7)
94                         {
95                                 this.flags |= FL_ONGROUND;
96                                 this.move_groundentity = trace_ent;
97                                 if (trace_ent.solid == SOLID_BSP)
98                                         this.move_suspendedinair = true;
99                                 this.velocity = '0 0 0';
100                                 this.avelocity = '0 0 0';
101                         }
102                         else
103                         {
104                                 this.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.flags & FL_ONGROUND)
114                         break;
115         }
116
117         //if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE && this.move_didgravity > 0 && !(this.flags & FL_ONGROUND))
118         //      this.velocity_z -= 0.5 * dt * (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
119
120         _Movetype_CheckWaterTransition(this);
121 }