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