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