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