]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/physics/movetypes/toss.qc
Transifex autosync
[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                 if(this.velocity == '0 0 0')
54                         break;
55
56                 vector move = this.velocity * movetime;
57                 if(!_Movetype_PushEntity(this, move, true))
58                         return; // teleported
59                 if (wasfreed(this))
60                         return;
61
62                 // NOTE: this is bmodelstartsolid in the engine
63                 if (trace_allsolid && trace_fraction == 0 && trace_ent.solid == SOLID_BSP)
64                 {
65                         // QC lacks pointers so we must save the old trace values
66                         float oldtrace_fraction = trace_fraction;
67                         vector oldtrace_plane_normal = trace_plane_normal;
68                         entity oldtrace_ent = trace_ent;
69                         _Movetype_UnstickEntity(this);
70                         trace_fraction = oldtrace_fraction;
71                         trace_plane_normal = oldtrace_plane_normal;
72                         trace_ent = oldtrace_ent;
73                         if(!_Movetype_PushEntity(this, move, true))
74                                 return; // teleported
75                         if (wasfreed(this))
76                                 return;
77                         if (trace_allsolid && trace_fraction == 0)
78                         {
79                                 // immovably stuck, don't waste CPU trying to move again
80                                 this.velocity = '0 0 0';
81                                 SET_ONGROUND(this);
82                                 return;
83                         }
84                 }
85
86                 if (trace_fraction == 1)
87                         break;
88
89                 movetime *= 1 - min(1, trace_fraction);
90
91                 if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
92                 {
93                         float bouncefac = (!this.bouncefactor) ? 1.0 : this.bouncefactor;
94                         this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1 + bouncefac);
95                         UNSET_ONGROUND(this);
96                         if(!GAMEPLAYFIX_SLIDEMOVEPROJECTILES(this))
97                                 movetime = 0;
98                 }
99                 else if (this.move_movetype == MOVETYPE_BOUNCE)
100                 {
101                         float bouncefac = (!this.bouncefactor) ? 0.5 : this.bouncefactor;
102                         float bstop = (!this.bouncestop) ? (60 / 800) : this.bouncestop;
103                         float grav = ((this.gravity) ? this.gravity : 1);
104
105                         this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1 + bouncefac);
106
107                         float d = trace_plane_normal * this.velocity;
108                         if(!GAMEPLAYFIX_GRENADEBOUNCESLOPES(this))
109                                 d = this.velocity.z;
110                         if (trace_plane_normal.z > 0.7 && d < PHYS_GRAVITY(this) * bstop * grav)
111                         {
112                                 SET_ONGROUND(this);
113                                 this.groundentity = trace_ent;
114                                 this.velocity = '0 0 0';
115                                 this.avelocity = '0 0 0';
116                                 movetime = 0;
117                         }
118                         else
119                         {
120                                 UNSET_ONGROUND(this);
121                                 if(!GAMEPLAYFIX_SLIDEMOVEPROJECTILES(this))
122                                         movetime = 0;
123                         }
124                 }
125                 else
126                 {
127                         this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1.0);
128                         if (trace_plane_normal.z > 0.7)
129                         {
130                                 SET_ONGROUND(this);
131                                 this.groundentity = trace_ent;
132                                 if (trace_ent.solid == SOLID_BSP)
133                                         this.move_suspendedinair = true;
134                                 this.velocity = '0 0 0';
135                                 this.avelocity = '0 0 0';
136                                 movetime = 0;
137                         }
138                         else
139                         {
140                                 UNSET_ONGROUND(this);
141                                 if(!GAMEPLAYFIX_SLIDEMOVEPROJECTILES(this))
142                                         movetime = 0;
143                         }
144                 }
145
146                 // DP revision 8905 (just, WHY...)
147                 //if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
148                         //break;
149
150                 // DP revision 8918 (WHY...)
151                 //if (IS_ONGROUND(this))
152                         //break;
153         }
154
155         if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE && this.move_didgravity > 0 && !IS_ONGROUND(this))
156                 this.velocity_z -= 0.5 * dt * ((this.gravity) ? this.gravity : 1) * PHYS_GRAVITY(this);
157
158         _Movetype_CheckWaterTransition(this);
159 }