Xonotic
toss.qc File Reference
#include "toss.qh"
+ Include dependency graph for toss.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void _Movetype_Physics_Toss (entity this, float dt)
 

Function Documentation

◆ _Movetype_Physics_Toss()

void _Movetype_Physics_Toss ( entity  this,
float  dt 
)

Definition at line 3 of file toss.qc.

References _Movetype_CheckVelocity(), _Movetype_CheckWaterTransition(), _Movetype_ClipVelocity(), _Movetype_PushEntity(), _Movetype_UnstickEntity(), absmax, absmin, angles, avelocity, bouncefactor, bouncestop, boxesoverlap(), entity(), GAMEPLAYFIX_GRENADEBOUNCESLOPES, GAMEPLAYFIX_NOAIRBORNCORPSE, GAMEPLAYFIX_SLIDEMOVEPROJECTILES, gravity, groundentity, IS_ONGROUND, min(), move_didgravity, move_movetype, move_suspendedinair, MOVETYPE_BOUNCE, MOVETYPE_BOUNCEMISSILE, MOVETYPE_TOSS, NOAIRBORNCORPSE_ALLOWSUSPENDED, NULL, SET_ONGROUND, SOLID_BSP, trace_ent, trace_fraction, trace_plane_normal, trace_startsolid, UNSET_ONGROUND, UPWARD_VELOCITY_CLEARS_ONGROUND, vector(), and velocity.

Referenced by _Movetype_Physics_ClientFrame(), and _Movetype_Physics_Frame().

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;
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 
32 
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  // NOTE: this is bmodelstartsolid in the engine
60  if (trace_startsolid && trace_ent.solid == SOLID_BSP)
61  {
62  // QC lacks pointers so we must save the old trace values
63  float oldtrace_fraction = trace_fraction;
64  vector oldtrace_plane_normal = trace_plane_normal;
65  entity oldtrace_ent = trace_ent;
67  trace_fraction = oldtrace_fraction;
68  trace_plane_normal = oldtrace_plane_normal;
69  trace_ent = oldtrace_ent;
70  if(!_Movetype_PushEntity(this, move, true, true))
71  return;
72  if (wasfreed(this))
73  return;
74  }
75 
76  if (trace_fraction == 1)
77  break;
78 
79  movetime *= 1 - min(1, trace_fraction);
80 
82  {
83  float bouncefac = (!this.bouncefactor) ? 1.0 : this.bouncefactor;
84  this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1 + bouncefac);
85  UNSET_ONGROUND(this);
87  movetime = 0;
88  }
89  else if (this.move_movetype == MOVETYPE_BOUNCE)
90  {
91  float bouncefac = (!this.bouncefactor) ? 0.5 : this.bouncefactor;
92  float bstop = (!this.bouncestop) ? (60 / 800) : this.bouncestop;
93  float grav = ((this.gravity) ? this.gravity : 1);
94 
95  this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1 + bouncefac);
96 
97  float d = trace_plane_normal * this.velocity;
99  d = this.velocity.z;
100  if (trace_plane_normal.z > 0.7 && d < PHYS_GRAVITY(this) * bstop * grav)
101  {
102  SET_ONGROUND(this);
103  this.groundentity = trace_ent;
104  this.velocity = '0 0 0';
105  this.avelocity = '0 0 0';
106  movetime = 0;
107  }
108  else
109  {
110  UNSET_ONGROUND(this);
112  movetime = 0;
113  }
114  }
115  else
116  {
117  this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1.0);
118  if (trace_plane_normal.z > 0.7)
119  {
120  SET_ONGROUND(this);
121  this.groundentity = trace_ent;
122  if (trace_ent.solid == SOLID_BSP)
123  this.move_suspendedinair = true;
124  this.velocity = '0 0 0';
125  this.avelocity = '0 0 0';
126  movetime = 0;
127  }
128  else
129  {
130  UNSET_ONGROUND(this);
132  movetime = 0;
133  }
134  }
135 
136  // DP revision 8905 (just, WHY...)
137  //if (this.move_movetype == MOVETYPE_BOUNCEMISSILE)
138  //break;
139 
140  // DP revision 8918 (WHY...)
141  //if (IS_ONGROUND(this))
142  //break;
143  }
144 
145  if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE && this.move_didgravity > 0 && !IS_ONGROUND(this))
146  this.velocity_z -= 0.5 * dt * ((this.gravity) ? this.gravity : 1) * PHYS_GRAVITY(this);
147 
149 }
#define UPWARD_VELOCITY_CLEARS_ONGROUND(s)
Definition: movetypes.qh:34
vector _Movetype_ClipVelocity(vector vel, vector norm, float f)
Definition: movetypes.qc:668
float MOVETYPE_TOSS
Definition: progsdefs.qc:252
entity() spawn
float MOVETYPE_BOUNCEMISSILE
Definition: progsdefs.qc:257
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
float bouncestop
vector avelocity
Definition: csprogsdefs.qc:105
float MOVETYPE_BOUNCE
Definition: progsdefs.qc:256
#define UNSET_ONGROUND(s)
Definition: movetypes.qh:18
float move_suspendedinair
Definition: movetypes.qh:94
float move_movetype
Definition: movetypes.qh:76
entity trace_ent
Definition: csprogsdefs.qc:40
int _Movetype_UnstickEntity(entity this)
Definition: movetypes.qc:622
vector absmax
Definition: csprogsdefs.qc:92
entity groundentity
Definition: movetypes.qh:93
void _Movetype_CheckWaterTransition(entity ent)
Definition: movetypes.qc:379
float bouncefactor
ERASEABLE float boxesoverlap(vector m1, vector m2, vector m3, vector m4)
requires that m2>m1 in all coordinates, and that m4>m3
Definition: vector.qh:73
#define NULL
Definition: post.qh:17
float move_didgravity
Definition: movetypes.qh:95
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float gravity
Definition: items.qh:16
const float SOLID_BSP
Definition: csprogsdefs.qc:248
#define SET_ONGROUND(s)
Definition: movetypes.qh:17
#define NOAIRBORNCORPSE_ALLOWSUSPENDED(s)
Definition: movetypes.qh:33
vector trace_plane_normal
Definition: csprogsdefs.qc:38
vector angles
Definition: csprogsdefs.qc:104
float trace_startsolid
Definition: csprogsdefs.qc:35
vector absmin
Definition: csprogsdefs.qc:92
bool _Movetype_PushEntity(entity this, vector push, bool failonstartsolid, bool dolink)
Definition: movetypes.qc:697
#define GAMEPLAYFIX_NOAIRBORNCORPSE(s)
Definition: movetypes.qh:32
void _Movetype_CheckVelocity(entity this)
Definition: movetypes.qc:339
vector velocity
Definition: csprogsdefs.qc:103
#define GAMEPLAYFIX_SLIDEMOVEPROJECTILES(s)
Definition: movetypes.qh:30
float trace_fraction
Definition: csprogsdefs.qc:36
#define GAMEPLAYFIX_GRENADEBOUNCESLOPES(s)
Definition: movetypes.qh:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function: