Xonotic
player.qc File Reference
#include "player.qh"
#include <common/mapobjects/_mod.qh>
#include <common/viewloc.qh>
+ Include dependency graph for player.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

float AdjustAirAccelQW (float accelqw, float factor)
 
void CheckPlayerJump (entity this)
 
void CheckWaterJump (entity this)
 
void CPM_PM_Aircontrol (entity this, float dt, vector wishdir, float wishspeed)
 
float GeomLerp (float a, float _lerp, float b)
 
bool IsFlying (entity this)
 
float IsMoveInDirection (vector mv, float ang)
 
bool PlayerJump (entity this)
 
void PM_Accelerate (entity this, float dt, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
 
void PM_AirAccelerate (entity this, float dt, vector wishdir, float wishspeed)
 
void PM_check_blocked (entity this)
 
void PM_check_frozen (entity this)
 
void PM_check_hitground (entity this)
 
void PM_check_nickspam (entity this)
 
void PM_check_punch (entity this, float dt)
 
void PM_check_slick (entity this)
 
bool PM_check_specialcommand (entity this, int buttons)
 
void PM_ClientMovement_UpdateStatus (entity this)
 
void PM_Footsteps (entity this)
 
void PM_jetpack (entity this, float maxspd_mod, float dt)
 
void sys_phys_update (entity this, float dt)
 

Variables

float jetpack_stopped
 

Function Documentation

◆ AdjustAirAccelQW()

float AdjustAirAccelQW ( float  accelqw,
float  factor 
)

Definition at line 213 of file player.qc.

References bound(), copysign(), and fabs().

Referenced by PM_Accelerate().

214 {
215  return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
216 }
float copysign(float e, float f)
Definition: mathlib.qc:225
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CheckPlayerJump()

void CheckPlayerJump ( entity  this)

Definition at line 473 of file player.qc.

References autocvar_sv_cheats, boolean, CheatImpulse(), CheckWaterJump(), entity(), ITEMS_STAT, jetpack_stopped, LOG_INFO, M_ARGV, maycheat, PHYS_AMMO_FUEL, PHYS_FROZEN, PHYS_INPUT_BUTTON_JETPACK, PHYS_INPUT_BUTTON_JUMP, PHYS_JETPACK_FUEL, PlayerJump(), UNSET_JUMP_HELD, waterlevel, and WATERLEVEL_SWIMMING.

Referenced by sys_phys_update().

474 {
475 #ifdef SVQC
476  bool was_flying = boolean(ITEMS_STAT(this) & IT_USING_JETPACK);
477 #endif
478  if (JETPACK_JUMP(this) < 2)
479  ITEMS_STAT(this) &= ~IT_USING_JETPACK;
480 
482  {
483  bool playerjump = PlayerJump(this); // required
484 
485  bool air_jump = !playerjump || M_ARGV(2, bool);
486  bool activate = (JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this)) || PHYS_INPUT_BUTTON_JETPACK(this);
487  bool has_fuel = !PHYS_JETPACK_FUEL(this) || PHYS_AMMO_FUEL(this) || (ITEMS_STAT(this) & IT_UNLIMITED_AMMO);
488 
489  if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
490  else if (this.jetpack_stopped) { }
491  else if (!has_fuel)
492  {
493 #ifdef SVQC
494  if (was_flying) // TODO: ran out of fuel message
495  Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
496  else if (activate)
497  Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
498 #endif
499  this.jetpack_stopped = true;
500  ITEMS_STAT(this) &= ~IT_USING_JETPACK;
501  }
502  else if (activate && !PHYS_FROZEN(this))
503  ITEMS_STAT(this) |= IT_USING_JETPACK;
504  }
505  else
506  {
507  this.jetpack_stopped = false;
508  ITEMS_STAT(this) &= ~IT_USING_JETPACK;
509  }
510  if (!PHYS_INPUT_BUTTON_JUMP(this))
511  UNSET_JUMP_HELD(this);
512 
513  if (this.waterlevel == WATERLEVEL_SWIMMING)
514  CheckWaterJump(this);
515 }
#define PHYS_INPUT_BUTTON_JUMP(s)
Definition: player.qh:147
#define PHYS_AMMO_FUEL(s)
Definition: player.qh:106
float waterlevel
Definition: progsdefs.qc:181
#define PHYS_JETPACK_FUEL(s)
Definition: player.qh:121
#define ITEMS_STAT(s)
Definition: player.qh:210
#define PHYS_FROZEN(s)
Definition: player.qh:114
#define UNSET_JUMP_HELD(s)
Definition: player.qh:201
#define M_ARGV(x, type)
Definition: events.qh:17
bool PlayerJump(entity this)
Definition: player.qc:330
#define PHYS_INPUT_BUTTON_JETPACK(s)
Definition: player.qh:158
const int WATERLEVEL_SWIMMING
Definition: movetypes.qh:13
float jetpack_stopped
Definition: player.qc:472
void CheckWaterJump(entity this)
Definition: player.qc:439
#define boolean(value)
Definition: bool.qh:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CheckWaterJump()

void CheckWaterJump ( entity  this)

Definition at line 439 of file player.qc.

References FL_WATERJUMP, flags, makevectors, movedir, normalize(), origin, SET_JUMP_HELD, teleport_time, time, trace_fraction, trace_plane_normal, v_angle, v_forward, and vector().

Referenced by CheckPlayerJump().

440 {
441 // check for a jump-out-of-water
442  makevectors(this.v_angle);
443  vector start = this.origin;
444  start_z += 8;
445  v_forward_z = 0;
447  vector end = start + v_forward*24;
448  traceline (start, end, true, this);
449  if (trace_fraction < 1)
450  { // solid at waist
451  start_z = start_z + this.maxs_z - 8;
452  end = start + v_forward*24;
453  this.movedir = trace_plane_normal * -50;
454  traceline(start, end, true, this);
455  if (trace_fraction == 1)
456  { // open at eye level
457  this.velocity_z = 225;
458  this.flags |= FL_WATERJUMP;
459  this.teleport_time = time + 2; // safety net
460  SET_JUMP_HELD(this);
461  }
462  }
463 }
float teleport_time
Definition: player.qh:212
vector v_angle
Definition: progsdefs.qc:161
origin
Definition: ent_cs.qc:114
vector movedir
Definition: progsdefs.qc:203
#define SET_JUMP_HELD(s)
Definition: player.qh:200
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float flags
Definition: csprogsdefs.qc:129
vector trace_plane_normal
Definition: csprogsdefs.qc:38
float time
Definition: csprogsdefs.qc:16
#define makevectors
Definition: post.qh:21
float trace_fraction
Definition: csprogsdefs.qc:36
float FL_WATERJUMP
Definition: progsdefs.qc:242
vector v_forward
Definition: csprogsdefs.qc:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CPM_PM_Aircontrol()

void CPM_PM_Aircontrol ( entity  this,
float  dt,
vector  wishdir,
float  wishspeed 
)

Definition at line 177 of file player.qc.

References bound(), IsMoveInDirection(), max(), movement, normalize(), PHYS_AIRCONTROL, PHYS_AIRCONTROL_BACKWARDS, PHYS_AIRCONTROL_PENALTY, PHYS_AIRCONTROL_POWER, PHYS_AIRCONTROL_SIDEWARDS, PHYS_MAXAIRSPEED, sqrt(), velocity, and vlen().

Referenced by sys_phys_simulate().

178 {
179  float movity = IsMoveInDirection(PHYS_CS(this).movement, 0);
180  if(PHYS_AIRCONTROL_BACKWARDS(this))
181  movity += IsMoveInDirection(PHYS_CS(this).movement, 180);
182  if(PHYS_AIRCONTROL_SIDEWARDS(this))
183  {
184  movity += IsMoveInDirection(PHYS_CS(this).movement, 90);
185  movity += IsMoveInDirection(PHYS_CS(this).movement, -90);
186  }
187 
188  float k = 32 * (2 * movity - 1);
189  if (k <= 0)
190  return;
191 
192  k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
193 
194  float zspeed = this.velocity_z;
195  this.velocity_z = 0;
196  float xyspeed = vlen(this.velocity);
197  this.velocity = normalize(this.velocity);
198 
199  float dot = this.velocity * wishdir;
200 
201  if (dot > 0) // we can't change direction while slowing down
202  {
203  k *= (dot ** PHYS_AIRCONTROL_POWER(this)) * dt;
204  xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
205  k *= PHYS_AIRCONTROL(this);
206  this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
207  }
208 
209  this.velocity = this.velocity * xyspeed;
210  this.velocity_z = zspeed;
211 }
#define PHYS_MAXAIRSPEED(s)
Definition: player.qh:130
#define PHYS_AIRCONTROL_SIDEWARDS(s)
Definition: player.qh:100
float IsMoveInDirection(vector mv, float ang)
Definition: player.qc:106
#define PHYS_AIRCONTROL_POWER(s)
Definition: player.qh:98
vector movement
#define PHYS_AIRCONTROL(s)
Definition: player.qh:96
#define PHYS_AIRCONTROL_BACKWARDS(s)
Definition: player.qh:99
#define PHYS_AIRCONTROL_PENALTY(s)
Definition: player.qh:97
vector velocity
Definition: csprogsdefs.qc:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GeomLerp()

float GeomLerp ( float  a,
float  _lerp,
float  b 
)

Definition at line 115 of file player.qc.

References fabs().

Referenced by sys_phys_simulate().

116 {
117  return a == 0 ? (_lerp < 1 ? 0 : b)
118  : b == 0 ? (_lerp > 0 ? 0 : a)
119  : a * (fabs(b / a) ** _lerp);
120 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsFlying()

bool IsFlying ( entity  this)

Definition at line 804 of file player.qc.

References CS(), CSQC_ClientMovement_PlayerMove_Frame(), csqcmodel_modelflags, entity(), frametime, intermission, IS_DEAD, IS_ONGROUND, IS_REAL_CLIENT, ITEMS_STAT, maxs, MF_ROCKET, mins, MOVE_NORMAL, origin, PM_UpdateButtons(), sys_phys_update(), trace_fraction, waterlevel, and WATERLEVEL_SWIMMING.

Referenced by Damage(), and sys_phys_update().

805 {
806  if(IS_ONGROUND(this))
807  return false;
808  if(this.waterlevel >= WATERLEVEL_SWIMMING)
809  return false;
810  tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 24', MOVE_NORMAL, this);
811  //traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
812  if(trace_fraction < 1)
813  return false;
814  return true;
815 }
float waterlevel
Definition: progsdefs.qc:181
const float MOVE_NORMAL
Definition: csprogsdefs.qc:252
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
vector maxs
Definition: csprogsdefs.qc:113
origin
Definition: ent_cs.qc:114
vector mins
Definition: csprogsdefs.qc:113
const int WATERLEVEL_SWIMMING
Definition: movetypes.qh:13
float trace_fraction
Definition: csprogsdefs.qc:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsMoveInDirection()

float IsMoveInDirection ( vector  mv,
float  ang 
)

Definition at line 106 of file player.qc.

References fabs(), RAD2DEG, and remainder().

Referenced by CPM_PM_Aircontrol(), and sys_phys_simulate().

107 {
108  if (mv_x == 0 && mv_y == 0)
109  return 0; // avoid division by zero
110  ang -= RAD2DEG * atan2(mv_y, mv_x);
111  ang = remainder(ang, 360) / 45;
112  return ang > 1 ? 0 : ang < -1 ? 0 : 1 - fabs(ang);
113 }
float RAD2DEG
Definition: csprogsdefs.qc:962
float remainder(float e, float f)
Definition: mathlib.qc:212
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PlayerJump()

bool PlayerJump ( entity  this)

Definition at line 330 of file player.qc.

References ANIMACTION_JUMP, animdecide_setaction(), CH_PLAYER, ftos(), IS_DUCKED, IS_JUMP_HELD, IS_ONGROUND, jumppadcount, lastground, LOG_TRACE, M_ARGV, maxs, mins, MOVE_NORMAL, MUTATOR_CALLHOOK, origin, PHYS_FRICTION_ONLAND, PHYS_FROZEN, PHYS_INPUT_BUTTON_CHAT, PHYS_INPUT_BUTTON_MINIGAME, PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS, PHYS_JUMPVELOCITY, PHYS_JUMPVELOCITY_CROUCH, PHYS_MAXSPEED, PHYS_TRACK_CANJUMP, player_blocked, SET_JUMP_HELD, stof(), time, trace_fraction, UNSET_ONGROUND, UNSET_ONSLICK, velocity, viewloc, vlen(), VOICETYPE_PLAYERSOUND, VOL_BASE, vtos(), WAS_ONGROUND, WAS_ONSLICK, waterlevel, and WATERLEVEL_SWIMMING.

Referenced by CheckPlayerJump().

331 {
332  if (PHYS_FROZEN(this))
333  return true; // no jumping in freezetag when frozen
334 
336  return true; // no jumping while typing
337 
338 #ifdef SVQC
339  if (this.player_blocked)
340  return true; // no jumping while blocked
341 #endif
342 
343  bool doublejump = false;
344  float mjumpheight = ((PHYS_JUMPVELOCITY_CROUCH(this) && IS_DUCKED(this)) ? PHYS_JUMPVELOCITY_CROUCH(this) : PHYS_JUMPVELOCITY(this));
345  bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
346 
347  if (MUTATOR_CALLHOOK(PlayerJump, this, mjumpheight, doublejump))
348  return true;
349 
350  mjumpheight = M_ARGV(1, float);
351  doublejump = M_ARGV(2, bool);
352 
353  if (this.waterlevel >= WATERLEVEL_SWIMMING)
354  {
355  if(this.viewloc)
356  {
357  doublejump = true;
358  mjumpheight *= 0.7;
359  track_jump = true;
360  }
361  else
362  {
363  this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
364  return true;
365  }
366  }
367 
368  if (!doublejump)
369  if (!IS_ONGROUND(this))
370  return IS_JUMP_HELD(this);
371 
372  if(PHYS_TRACK_CANJUMP(this))
373  track_jump = true;
374 
375  if (track_jump)
376  if (IS_JUMP_HELD(this))
377  return true;
378 
379  // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
380  // velocity bounds. Final velocity is bound between (jumpheight *
381  // min + jumpheight) and (jumpheight * max + jumpheight);
382 
383  if(PHYS_JUMPSPEEDCAP_MIN != "")
384  {
385  float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
386 
387  if (this.velocity_z < minjumpspeed)
388  mjumpheight += minjumpspeed - this.velocity_z;
389  }
390 
391  if(PHYS_JUMPSPEEDCAP_MAX != "")
392  {
393  // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
394  tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
395 
396  if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(this)))
397  {
398  float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
399 
400  if (this.velocity_z > maxjumpspeed)
401  mjumpheight -= this.velocity_z - maxjumpspeed;
402  }
403  }
404 
405  if (!WAS_ONGROUND(this) && !WAS_ONSLICK(this))
406  {
407 #ifdef SVQC
408  if(autocvar_speedmeter)
409  LOG_TRACE("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")");
410 #endif
411  if(this.lastground < time - 0.3)
412  {
413  float f = (1 - PHYS_FRICTION_ONLAND(this));
414  this.velocity_x *= f;
415  this.velocity_y *= f;
416  }
417 #ifdef SVQC
418  if(this.jumppadcount > 1)
419  LOG_TRACE(ftos(this.jumppadcount), "x jumppad combo");
420  this.jumppadcount = 0;
421 #endif
422  }
423 
424  this.velocity_z += mjumpheight;
425 
426  UNSET_ONGROUND(this);
427  UNSET_ONSLICK(this);
428  SET_JUMP_HELD(this);
429 
430 #ifdef SVQC
432 
433  if (autocvar_g_jump_grunt)
434  PlayerSound(this, playersound_jump, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
435 #endif
436  return true;
437 }
#define UNSET_ONSLICK(s)
Definition: movetypes.qh:21
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition: player.qh:155
#define WAS_ONGROUND(s)
Definition: player.qh:203
const int VOICETYPE_PLAYERSOUND
Definition: globalsound.qh:64
float waterlevel
Definition: progsdefs.qc:181
#define IS_DUCKED(s)
Definition: player.qh:206
const int ANIMACTION_JUMP
Definition: animdecide.qh:141
const float MOVE_NORMAL
Definition: csprogsdefs.qc:252
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
vector maxs
Definition: csprogsdefs.qc:113
float lastground
Definition: player.qh:61
#define WAS_ONSLICK(s)
Definition: player.qh:204
#define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(s)
Definition: player.qh:126
float jumppadcount
Definition: jumppads.qh:15
origin
Definition: ent_cs.qc:114
#define UNSET_ONGROUND(s)
Definition: movetypes.qh:18
#define PHYS_FROZEN(s)
Definition: player.qh:114
vector mins
Definition: csprogsdefs.qc:113
void animdecide_setaction(entity e, float action, float restart)
Definition: animdecide.qc:338
const float VOL_BASE
Definition: sound.qh:36
#define M_ARGV(x, type)
Definition: events.qh:17
#define SET_JUMP_HELD(s)
Definition: player.qh:200
#define PHYS_JUMPVELOCITY(s)
Definition: player.qh:127
entity viewloc
Definition: viewloc.qh:13
#define LOG_TRACE(...)
Definition: log.qh:81
bool PlayerJump(entity this)
Definition: player.qc:330
const int WATERLEVEL_SWIMMING
Definition: movetypes.qh:13
const int CH_PLAYER
Definition: sound.qh:20
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
bool player_blocked
Definition: client.qh:337
#define IS_JUMP_HELD(s)
Definition: player.qh:199
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
#define PHYS_MAXSPEED(s)
Definition: player.qh:132
float trace_fraction
Definition: csprogsdefs.qc:36
#define PHYS_JUMPVELOCITY_CROUCH(s)
Definition: player.qh:128
#define PHYS_INPUT_BUTTON_MINIGAME(s)
Definition: player.qh:160
#define PHYS_TRACK_CANJUMP(s)
Definition: player.qh:136
#define PHYS_FRICTION_ONLAND(s)
Definition: player.qh:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_Accelerate()

void PM_Accelerate ( entity  this,
float  dt,
vector  wishdir,
float  wishspeed,
float  wishspeed0,
float  accel,
float  accelqw,
float  stretchfactor,
float  sidefric,
float  speedlimit 
)

Definition at line 223 of file player.qc.

References AdjustAirAccelQW(), bound(), fabs(), max(), sqrt(), vec2, vector(), velocity, and vlen().

Referenced by sys_phys_simulate().

224 {
225  float speedclamp = stretchfactor > 0 ? stretchfactor
226  : accelqw < 0 ? 1 // full clamping, no stretch
227  : -1; // no clamping
228 
229  accelqw = fabs(accelqw);
230 
231  if (GAMEPLAYFIX_Q2AIRACCELERATE)
232  wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
233 
234  float vel_straight = this.velocity * wishdir;
235  float vel_z = this.velocity_z;
236  vector vel_xy = vec2(this.velocity);
237  vector vel_perpend = vel_xy - vel_straight * wishdir;
238 
239  float step = accel * dt * wishspeed0;
240 
241  float vel_xy_current = vlen(vel_xy);
242  if (speedlimit)
243  accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
244  float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
245  float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
246  vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
247  vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
248 
249  if (sidefric < 0 && (vel_perpend*vel_perpend))
250  // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
251  {
252  float f = max(0, 1 + dt * wishspeed * sidefric);
253  float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
254  // assume: themin > 1
255  // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
256  // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
257  // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
258  // obviously, this cannot be
259  if (themin <= 0)
260  vel_perpend *= f;
261  else
262  {
263  themin = sqrt(themin);
264  vel_perpend *= max(themin, f);
265  }
266  }
267  else
268  vel_perpend *= max(0, 1 - dt * wishspeed * sidefric);
269 
270  vel_xy = vel_straight * wishdir + vel_perpend;
271 
272  if (speedclamp >= 0)
273  {
274  float vel_xy_preclamp;
275  vel_xy_preclamp = vlen(vel_xy);
276  if (vel_xy_preclamp > 0) // prevent division by zero
277  {
278  vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
279  if (vel_xy_current < vel_xy_preclamp)
280  vel_xy *= (vel_xy_current / vel_xy_preclamp);
281  }
282  }
283 
284  this.velocity = vel_xy + vel_z * '0 0 1';
285 }
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float AdjustAirAccelQW(float accelqw, float factor)
Definition: player.qc:213
#define vec2(...)
Definition: vector.qh:90
vector velocity
Definition: csprogsdefs.qc:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_AirAccelerate()

void PM_AirAccelerate ( entity  this,
float  dt,
vector  wishdir,
float  wishspeed 
)

Definition at line 287 of file player.qc.

References max(), min(), normalize(), PHYS_MAXSPEED, PHYS_WARSOWBUNNY_ACCEL, PHYS_WARSOWBUNNY_AIRFORWARDACCEL, PHYS_WARSOWBUNNY_BACKTOSIDERATIO, PHYS_WARSOWBUNNY_TOPSPEED, PHYS_WARSOWBUNNY_TURNACCEL, vector(), velocity, and vlen().

Referenced by sys_phys_simulate().

288 {
289  if (wishspeed == 0)
290  return;
291 
292  vector curvel = this.velocity;
293  curvel_z = 0;
294  float curspeed = vlen(curvel);
295 
296  if (wishspeed > curspeed * 1.01)
297  wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * dt);
298  else
299  {
300  float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
301  wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * dt;
302  }
303  vector wishvel = wishdir * wishspeed;
304  vector acceldir = wishvel - curvel;
305  float addspeed = vlen(acceldir);
306  acceldir = normalize(acceldir);
307 
308  float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * dt);
309 
310  if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
311  {
312  vector curdir = normalize(curvel);
313  float dot = acceldir * curdir;
314  if (dot < 0)
315  acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
316  }
317 
318  this.velocity += accelspeed * acceldir;
319 }
#define PHYS_WARSOWBUNNY_AIRFORWARDACCEL(s)
Definition: player.qh:139
#define PHYS_WARSOWBUNNY_BACKTOSIDERATIO(s)
Definition: player.qh:140
#define PHYS_WARSOWBUNNY_TOPSPEED(s)
Definition: player.qh:141
#define PHYS_WARSOWBUNNY_TURNACCEL(s)
Definition: player.qh:142
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define PHYS_WARSOWBUNNY_ACCEL(s)
Definition: player.qh:138
vector velocity
Definition: csprogsdefs.qc:103
#define PHYS_MAXSPEED(s)
Definition: player.qh:132
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_check_blocked()

void PM_check_blocked ( entity  this)

Definition at line 683 of file player.qc.

References disableclientprediction, PHYS_INPUT_BUTTON_CHAT, PHYS_INPUT_BUTTON_MINIGAME, and player_blocked.

Referenced by sys_phys_update().

684 {
686  PHYS_CS(this).movement = '0 0 0';
687 #ifdef SVQC
688  if (!this.player_blocked)
689  return;
690  PHYS_CS(this).movement = '0 0 0';
691  this.disableclientprediction = 1;
692 #endif
693 }
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition: player.qh:155
float disableclientprediction
bool player_blocked
Definition: client.qh:337
#define PHYS_INPUT_BUTTON_MINIGAME(s)
Definition: player.qh:160
+ Here is the caller graph for this function:

◆ PM_check_frozen()

void PM_check_frozen ( entity  this)

Definition at line 609 of file player.qc.

References bound(), IS_CLIENT, movement, PHYS_DODGING_FROZEN, and PHYS_FROZEN.

Referenced by sys_phys_update().

610 {
611  if (!PHYS_FROZEN(this))
612  return;
613  if (PHYS_DODGING_FROZEN(this) && IS_CLIENT(this))
614  {
615  // bind movement to a very slow speed so dodging can use .movement for directional calculations
616  PHYS_CS(this).movement_x = bound(-2, PHYS_CS(this).movement.x, 2);
617  PHYS_CS(this).movement_y = bound(-2, PHYS_CS(this).movement.y, 2);
618  PHYS_CS(this).movement_z = bound(-2, PHYS_CS(this).movement.z, 2);
619  }
620  else
621  PHYS_CS(this).movement = '0 0 0';
622 }
#define IS_CLIENT(v)
Definition: utils.qh:13
#define PHYS_DODGING_FROZEN(s)
Definition: player.qh:108
#define PHYS_FROZEN(s)
Definition: player.qh:114
vector movement
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_check_hitground()

void PM_check_hitground ( entity  this)

Definition at line 624 of file player.qc.

References CH_PLAYER, entity(), hook, IS_DUCKED, ladder_entity, MAX_WEAPONSLOTS, maxs, mins, MOVE_NOMONSTERS, origin, Q3SURFACEFLAG_METALSTEPS, Q3SURFACEFLAG_NOSTEPS, random(), time, trace_dphitq3surfaceflags, VOICETYPE_PLAYERSOUND, VOL_BASE, VOL_MUFFLED, wasFlying, waterlevel, WATERLEVEL_SWIMMING, and weaponentities.

Referenced by sys_phys_update().

625 {
626 #ifdef SVQC
627  if (!this.wasFlying) return;
628  this.wasFlying = false;
629  if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
630  if (this.ladder_entity) return;
631  for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
632  {
633  .entity weaponentity = weaponentities[slot];
634  if(this.(weaponentity).hook)
635  return;
636  }
637  this.nextstep = time + 0.3 + random() * 0.1;
639  tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
642  ? GS_FALL_METAL
643  : GS_FALL;
644  float vol = ((IS_DUCKED(this)) ? VOL_MUFFLED : VOL_BASE);
645  GlobalSound(this, gs, CH_PLAYER, vol, VOICETYPE_PLAYERSOUND);
646 #endif
647 }
entity hook
Definition: hook.qh:19
const float VOL_MUFFLED
Definition: sound.qh:38
float trace_dphitq3surfaceflags
const int VOICETYPE_PLAYERSOUND
Definition: globalsound.qh:64
float waterlevel
Definition: progsdefs.qc:181
#define IS_DUCKED(s)
Definition: player.qh:206
entity() spawn
vector maxs
Definition: csprogsdefs.qc:113
bool wasFlying
Definition: player.qh:62
float Q3SURFACEFLAG_METALSTEPS
origin
Definition: ent_cs.qc:114
float Q3SURFACEFLAG_NOSTEPS
const float MOVE_NOMONSTERS
Definition: csprogsdefs.qc:253
vector mins
Definition: csprogsdefs.qc:113
const int MAX_WEAPONSLOTS
Definition: weapon.qh:13
const float VOL_BASE
Definition: sound.qh:36
entity ladder_entity
Definition: ladder.qh:11
const int WATERLEVEL_SWIMMING
Definition: movetypes.qh:13
const int CH_PLAYER
Definition: sound.qh:20
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_check_nickspam()

void PM_check_nickspam ( entity  this)

Definition at line 563 of file player.qc.

References fixangle, nickspamcount, nickspamtime, PHYS_INPUT_BUTTON_ATCK, PHYS_INPUT_BUTTON_ATCK2, PHYS_INPUT_BUTTON_CROUCH, PHYS_INPUT_BUTTON_HOOK, PHYS_INPUT_BUTTON_JUMP, PHYS_INPUT_BUTTON_USE, PHYS_INPUT_BUTTON_ZOOM, random(), and time.

Referenced by sys_phys_monitor().

564 {
565 #ifdef SVQC
566  if (time >= this.nickspamtime)
567  return;
568  if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
569  {
570  // slight annoyance for nick change scripts
571  PHYS_CS(this).movement = -1 * PHYS_CS(this).movement;
573 
574  if (this.nickspamcount >= autocvar_g_nick_flood_penalty_red) // if you are persistent and the slight annoyance above does not stop you, I'll show you!
575  {
576  this.v_angle_x = random() * 360;
577  this.v_angle_y = random() * 360;
578  // at least I'm not forcing retardedview by also assigning to angles_z
579  this.fixangle = true;
580  }
581  }
582 #endif
583 }
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition: player.qh:148
#define PHYS_INPUT_BUTTON_JUMP(s)
Definition: player.qh:147
#define PHYS_INPUT_BUTTON_CROUCH(s)
Definition: player.qh:150
#define PHYS_INPUT_BUTTON_HOOK(s)
Definition: player.qh:151
float nickspamcount
Definition: client.qh:321
#define PHYS_INPUT_BUTTON_ZOOM(s)
Definition: player.qh:149
#define PHYS_INPUT_BUTTON_USE(s)
Definition: player.qh:154
float fixangle
Definition: progsdefs.qc:160
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition: player.qh:146
float nickspamtime
Definition: client.qh:320
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_check_punch()

void PM_check_punch ( entity  this,
float  dt 
)

Definition at line 585 of file player.qc.

References normalize(), punchangle, punchvector, and vlen().

Referenced by sys_phys_monitor().

586 {
587 #ifdef SVQC
588  if (this.punchangle != '0 0 0')
589  {
590  float f = vlen(this.punchangle) - 10 * dt;
591  if (f > 0)
592  this.punchangle = normalize(this.punchangle) * f;
593  else
594  this.punchangle = '0 0 0';
595  }
596 
597  if (this.punchvector != '0 0 0')
598  {
599  float f = vlen(this.punchvector) - 30 * dt;
600  if (f > 0)
601  this.punchvector = normalize(this.punchvector) * f;
602  else
603  this.punchvector = '0 0 0';
604  }
605 #endif
606 }
vector punchangle
vector punchvector
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_check_slick()

void PM_check_slick ( entity  this)

Definition at line 670 of file player.qc.

References IS_ONGROUND, maxs, mins, MOVE_NOMONSTERS, origin, Q3SURFACEFLAG_SLICK, SET_ONSLICK, trace_dphitq3surfaceflags, and UNSET_ONSLICK.

Referenced by sys_phys_update().

671 {
672  if(!IS_ONGROUND(this))
673  return;
674 
676  tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
678  SET_ONSLICK(this);
679  else
680  UNSET_ONSLICK(this);
681 }
#define UNSET_ONSLICK(s)
Definition: movetypes.qh:21
float trace_dphitq3surfaceflags
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
vector maxs
Definition: csprogsdefs.qc:113
float Q3SURFACEFLAG_SLICK
origin
Definition: ent_cs.qc:114
const float MOVE_NOMONSTERS
Definition: csprogsdefs.qc:253
vector mins
Definition: csprogsdefs.qc:113
#define SET_ONSLICK(s)
Definition: movetypes.qh:20
+ Here is the caller graph for this function:

◆ PM_check_specialcommand()

bool PM_check_specialcommand ( entity  this,
int  buttons 
)

Definition at line 530 of file player.qc.

References BIT, CS(), strlen(), and substring().

Referenced by sys_phys_override().

531 {
532 #ifdef SVQC
533  string c;
534  switch (buttons)
535  {
536  // buttons mapped in PHYS_INPUT_BUTTON_MASK
537  case 0: c = "x"; break;
538  case BIT(0): c = "1"; break;
539  case BIT(2): c = " "; break;
540  case BIT(7): c = "s"; break;
541  case BIT(8): c = "w"; break;
542  case BIT(9): c = "a"; break;
543  case BIT(10): c = "d"; break;
544  default: c = "?";
545  }
546 
547  if (c == substring(specialcommand, CS(this).specialcommand_pos, 1))
548  {
549  CS(this).specialcommand_pos += 1;
550  if (CS(this).specialcommand_pos >= strlen(specialcommand))
551  {
552  CS(this).specialcommand_pos = 0;
553  SpecialCommand(this);
554  return true;
555  }
556  }
557  else if (CS(this).specialcommand_pos && (c != substring(specialcommand, CS(this).specialcommand_pos - 1, 1)))
558  CS(this).specialcommand_pos = 0;
559 #endif
560  return false;
561 }
ClientState CS(Client this)
Definition: state.qh:47
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition: bits.qh:8
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_ClientMovement_UpdateStatus()

void PM_ClientMovement_UpdateStatus ( entity  this)

Definition at line 122 of file player.qc.

References _Movetype_CheckWater(), entity(), IS_DEAD, IS_DUCKED, IS_PLAYER, M_ARGV, MAX_WEAPONSLOTS, movement, MUTATOR_CALLHOOK, origin, PHYS_INPUT_BUTTON_CROUCH, SET_DUCKED, trace_startsolid, UNSET_DUCKED, view_ofs, viewloc, VIEWLOC_FREEMOVE, viewmodels, and weaponentities.

Referenced by sys_phys_fix().

123 {
124  if(!IS_PLAYER(this))
125  return;
126 
127  bool have_hook = false;
128  for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
129  {
130  #if defined(CSQC)
131  entity wepent = viewmodels[slot];
132  #elif defined(SVQC)
133  .entity weaponentity = weaponentities[slot];
134  entity wepent = this.(weaponentity);
135  #endif
136  if(wepent.hook && !wasfreed(wepent.hook))
137  {
138  have_hook = true;
139  break;
140  }
141  }
142  bool do_crouch = PHYS_INPUT_BUTTON_CROUCH(this);
143  if(this.viewloc && !(this.viewloc.spawnflags & VIEWLOC_FREEMOVE) && PHYS_CS(this).movement.x < 0)
144  do_crouch = true;
145  if (have_hook) {
146  do_crouch = false;
147  //} else if (this.waterlevel >= WATERLEVEL_SWIMMING) {
148  //do_crouch = false;
149  } else if (PHYS_INVEHICLE(this)) {
150  do_crouch = false;
151  } else if (STAT(FROZEN, this) || IS_DEAD(this)) {
152  do_crouch = false;
153  }
154 
155  MUTATOR_CALLHOOK(PlayerCanCrouch, this, do_crouch);
156  do_crouch = M_ARGV(1, bool);
157 
158  if (do_crouch) {
159  if (!IS_DUCKED(this)) {
160  SET_DUCKED(this);
161  this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, this);
162  setsize(this, STAT(PL_CROUCH_MIN, this), STAT(PL_CROUCH_MAX, this));
163  // setanim(this, this.anim_duck, false, true, true); // this anim is BROKEN anyway
164  }
165  } else if (IS_DUCKED(this)) {
166  tracebox(this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), this.origin, false, this);
167  if (!trace_startsolid) {
168  UNSET_DUCKED(this);
169  this.view_ofs = STAT(PL_VIEW_OFS, this);
170  setsize(this, STAT(PL_MIN, this), STAT(PL_MAX, this));
171  }
172  }
173 
174  _Movetype_CheckWater(this); // needs to be run on the client, might as well use the latest on the server too!
175 }
#define PHYS_INPUT_BUTTON_CROUCH(s)
Definition: player.qh:150
vector view_ofs
Definition: progsdefs.qc:151
bool _Movetype_CheckWater(entity this)
Definition: movetypes.qc:345
#define IS_DUCKED(s)
Definition: player.qh:206
entity viewmodels[MAX_WEAPONSLOTS]
Definition: view.qh:104
entity() spawn
origin
Definition: ent_cs.qc:114
#define UNSET_DUCKED(s)
Definition: player.qh:208
const int MAX_WEAPONSLOTS
Definition: weapon.qh:13
#define M_ARGV(x, type)
Definition: events.qh:17
#define IS_DEAD(s)
Definition: utils.qh:26
vector movement
#define SET_DUCKED(s)
Definition: player.qh:207
entity viewloc
Definition: viewloc.qh:13
const int VIEWLOC_FREEMOVE
Definition: viewloc.qh:6
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
float trace_startsolid
Definition: csprogsdefs.qc:35
#define IS_PLAYER(v)
Definition: utils.qh:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_Footsteps()

void PM_Footsteps ( entity  this)

Definition at line 649 of file player.qc.

References CH_PLAYER, entity(), IS_DUCKED, lastground, maxs, mins, MOVE_NOMONSTERS, origin, Q3SURFACEFLAG_METALSTEPS, Q3SURFACEFLAG_NOSTEPS, random(), time, trace_dphitq3surfaceflags, vdist, velocity, VOICETYPE_PLAYERSOUND, and VOL_BASE.

Referenced by sys_phys_update().

650 {
651 #ifdef SVQC
652  if (!autocvar_g_footsteps) return;
653  if (IS_DUCKED(this)) return;
654  if (time >= this.lastground + 0.2) return;
655  if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
656  if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
657  {
658  this.nextstep = time + 0.3 + random() * 0.1;
660  tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
663  ? GS_STEP_METAL
664  : GS_STEP;
665  GlobalSound(this, gs, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
666  }
667 #endif
668 }
float trace_dphitq3surfaceflags
const int VOICETYPE_PLAYERSOUND
Definition: globalsound.qh:64
#define IS_DUCKED(s)
Definition: player.qh:206
entity() spawn
vector maxs
Definition: csprogsdefs.qc:113
float lastground
Definition: player.qh:61
float Q3SURFACEFLAG_METALSTEPS
origin
Definition: ent_cs.qc:114
float Q3SURFACEFLAG_NOSTEPS
const float MOVE_NOMONSTERS
Definition: csprogsdefs.qc:253
vector mins
Definition: csprogsdefs.qc:113
const float VOL_BASE
Definition: sound.qh:36
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
const int CH_PLAYER
Definition: sound.qh:20
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PM_jetpack()

void PM_jetpack ( entity  this,
float  maxspd_mod,
float  dt 
)

Definition at line 695 of file player.qc.

References autocvar_g_balance_pause_fuel_regen, best, bound(), ITEMS_STAT, makevectors, max(), min(), normalize(), pauseregen_finished, PHYS_AMMO_FUEL, PHYS_INPUT_BUTTON_CROUCH, PHYS_JETPACK_ACCEL_SIDE, PHYS_JETPACK_ACCEL_UP, PHYS_JETPACK_ANTIGRAVITY, PHYS_JETPACK_FUEL, PHYS_JETPACK_MAXSPEED_SIDE, PHYS_JETPACK_MAXSPEED_UP, PHYS_JETPACK_REVERSE_THRUST, PHYS_MAXAIRSPEED, sqrt(), TakeResource(), time, UNSET_ONGROUND, v_angle, v_forward, v_right, vector(), velocity, and vlen().

Referenced by sys_phys_update().

696 {
697  //makevectors(this.v_angle.y * '0 1 0');
698  makevectors(this.v_angle);
699  vector wishvel = v_forward * PHYS_CS(this).movement_x
700  + v_right * PHYS_CS(this).movement_y;
701  // add remaining speed as Z component
702  float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
703  // fix speedhacks :P
704  wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
705  // add the unused velocity as up component
706  wishvel_z = 0;
707 
708  // if (PHYS_INPUT_BUTTON_JUMP(this))
709  wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
710 
711  // it is now normalized, so...
712  float a_side = PHYS_JETPACK_ACCEL_SIDE(this);
713  float a_up = PHYS_JETPACK_ACCEL_UP(this);
714  float a_add = PHYS_JETPACK_ANTIGRAVITY(this) * PHYS_GRAVITY(this);
715 
717 
718  wishvel_x *= a_side;
719  wishvel_y *= a_side;
720  wishvel_z *= a_up;
721  wishvel_z += a_add;
722 
723  if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(this)) { wishvel_z *= -1; }
724 
725  float best = 0;
727  // finding the maximum over all vectors of above form
728  // with wishvel having an absolute value of 1
730  // we're finding the maximum over
731  // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
732  // for z in the range from -1 to 1
734  // maximum is EITHER attained at the single extreme point:
735  float a_diff = a_side * a_side - a_up * a_up;
736  float f;
737  if (a_diff != 0)
738  {
739  f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
740  if (f > -1 && f < 1) // can it be attained?
741  {
742  best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
743  //print("middle\n");
744  }
745  }
746  // OR attained at z = 1:
747  f = (a_up + a_add) * (a_up + a_add);
748  if (f > best)
749  {
750  best = f;
751  //print("top\n");
752  }
753  // OR attained at z = -1:
754  f = (a_up - a_add) * (a_up - a_add);
755  if (f > best)
756  {
757  best = f;
758  //print("bottom\n");
759  }
760  best = sqrt(best);
762 
763  //print("best possible acceleration: ", ftos(best), "\n");
764 
765  float fxy, fz;
766  fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE(this), 1);
767  if (wishvel_z - PHYS_GRAVITY(this) > 0)
768  fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
769  else
770  fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
771 
772  float fvel;
773  fvel = vlen(wishvel);
774  wishvel_x *= fxy;
775  wishvel_y *= fxy;
776  wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
777 
778  fvel = min(1, vlen(wishvel) / best);
779  if (PHYS_JETPACK_FUEL(this) && !(ITEMS_STAT(this) & IT_UNLIMITED_AMMO))
780  f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL(this) * dt * fvel));
781  else
782  f = 1;
783 
784  //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
785 
786  if (f > 0 && wishvel != '0 0 0')
787  {
788  this.velocity = this.velocity + wishvel * f * dt;
789  UNSET_ONGROUND(this);
790 
791 #ifdef SVQC
792  if (!(ITEMS_STAT(this) & IT_UNLIMITED_AMMO))
793  TakeResource(this, RES_FUEL, PHYS_JETPACK_FUEL(this) * dt * fvel * f);
794 
795  ITEMS_STAT(this) |= IT_USING_JETPACK;
796 
797  // jetpack also inhibits health regeneration, but only for 1 second
799 #endif
800  }
801 }
#define PHYS_INPUT_BUTTON_CROUCH(s)
Definition: player.qh:150
#define PHYS_MAXAIRSPEED(s)
Definition: player.qh:130
#define PHYS_JETPACK_MAXSPEED_UP(s)
Definition: player.qh:123
#define PHYS_JETPACK_REVERSE_THRUST(s)
Definition: player.qh:124
#define PHYS_AMMO_FUEL(s)
Definition: player.qh:106
vector v_angle
Definition: progsdefs.qc:161
#define PHYS_JETPACK_FUEL(s)
Definition: player.qh:121
float autocvar_g_balance_pause_fuel_regen
Definition: sv_resources.qh:33
#define UNSET_ONGROUND(s)
Definition: movetypes.qh:18
#define ITEMS_STAT(s)
Definition: player.qh:210
void TakeResource(entity receiver, Resource res_type, float amount)
Takes an entity some resource.
Definition: cl_resources.qc:31
#define PHYS_JETPACK_ANTIGRAVITY(s)
Definition: player.qh:120
#define PHYS_JETPACK_ACCEL_UP(s)
Definition: player.qh:119
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define PHYS_JETPACK_MAXSPEED_SIDE(s)
Definition: player.qh:122
vector v_right
Definition: csprogsdefs.qc:31
float pauseregen_finished
Definition: client.qh:342
best
Definition: all.qh:77
#define PHYS_JETPACK_ACCEL_SIDE(s)
Definition: player.qh:118
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
#define makevectors
Definition: post.qh:21
vector v_forward
Definition: csprogsdefs.qc:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sys_phys_update()

void sys_phys_update ( entity  this,
float  dt 
)

Definition at line 11 of file physics.qc.

Referenced by IsFlying().

12 {
13  if (!IS_CLIENT(this)) {
14  sys_phys_simulate_simple(this, dt);
15  return;
16  }
17  sys_in_update(this, dt);
18 
19  sys_phys_fix(this, dt);
20  if (sys_phys_override(this, dt))
21  return;
22 
23  sys_phys_monitor(this, dt);
24 
25  PHYS_CS(this).movement_old = PHYS_CS(this).movement;
26  PHYS_CS(this).v_angle_old = this.v_angle;
27  PHYS_CS(this).buttons_old = PHYS_INPUT_BUTTON_MASK(this);
28 
29  sys_phys_ai(this);
30 
32 
33  if (IS_SVQC) {
34  if (this.move_movetype == MOVETYPE_NONE) { return; }
35  // when we get here, disableclientprediction cannot be 2
36  if(this.move_movetype == MOVETYPE_FOLLOW) // not compatible with prediction
37  this.disableclientprediction = 1;
38  else if(this.move_qcphysics)
39  this.disableclientprediction = -1;
40  else
41  this.disableclientprediction = 0;
42  }
43 
45 
46  PM_check_frozen(this);
47 
48  PM_check_blocked(this);
49 
50  float maxspeed_mod = 1;
51 
52 // conveyors: first fix velocity
53  if (this.conveyor.active) { this.velocity -= this.conveyor.movedir; }
54  MUTATOR_CALLHOOK(PlayerPhysics, this, dt);
55 
56  if (!IS_PLAYER(this)) {
58  maxspeed_mod = STAT(SPECTATORSPEED, this);
59  }
60  sys_phys_fixspeed(this, maxspeed_mod);
61 
62  if (IS_DEAD(this)) {
63  // handle water here
64  vector midpoint = ((this.absmin + this.absmax) * 0.5);
65  int cont = pointcontents(midpoint);
66  if (cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME) {
67  this.velocity = this.velocity * 0.5;
68 
69  // do we want this?
70  // if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
71  // { this.velocity_z = 70; }
72  }
73  sys_phys_postupdate(this);
74  return;
75  }
76 
77  PM_check_slick(this);
78 
79  if (IS_SVQC && !PHYS_FIXANGLE(this)) { this.angles = '0 1 0' * this.v_angle.y; }
80  if (IS_PLAYER(this)) {
81  if (IS_ONGROUND(this)) {
82  PM_check_hitground(this);
83  PM_Footsteps(this);
84  } else if (IsFlying(this)) {
85  this.wasFlying = true;
86  }
87  CheckPlayerJump(this);
88  }
89 
90  if (this.flags & FL_WATERJUMP) {
91  this.velocity_x = this.movedir.x;
92  this.velocity_y = this.movedir.y;
93  if (time > this.teleport_time || this.waterlevel == WATERLEVEL_NONE) {
94  this.flags &= ~FL_WATERJUMP;
95  this.teleport_time = 0;
96  }
97  } else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod, dt)) {
98  // handled
99  } else if (this.move_movetype == MOVETYPE_NOCLIP
100  || this.move_movetype == MOVETYPE_FLY
102  || MUTATOR_CALLHOOK(IsFlying, this)) {
103  this.com_phys_friction = PHYS_FRICTION(this);
104  this.com_phys_vel_max = PHYS_MAXSPEED(this) * maxspeed_mod;
105  this.com_phys_acc_rate = PHYS_ACCELERATE(this) * maxspeed_mod;
106  this.com_phys_friction_air = true;
107  sys_phys_simulate(this, dt);
108  this.com_phys_friction_air = false;
109  } else if (this.waterlevel >= WATERLEVEL_SWIMMING) {
110  this.com_phys_vel_max = PHYS_MAXSPEED(this) * maxspeed_mod;
111  this.com_phys_acc_rate = PHYS_ACCELERATE(this) * maxspeed_mod;
112  this.com_phys_water = true;
113  sys_phys_simulate(this, dt);
114  this.com_phys_water = false;
115  this.jumppadcount = 0;
116  } else if (this.ladder_entity) {
117  this.com_phys_friction = PHYS_FRICTION(this);
118  this.com_phys_vel_max = PHYS_MAXSPEED(this) * maxspeed_mod;
119  this.com_phys_acc_rate = PHYS_ACCELERATE(this) * maxspeed_mod;
120  this.com_phys_gravity = -PHYS_GRAVITY(this) * dt;
121  if (PHYS_ENTGRAVITY(this)) { this.com_phys_gravity *= PHYS_ENTGRAVITY(this); }
122  this.com_phys_ladder = true;
123  this.com_phys_friction_air = true;
124  sys_phys_simulate(this, dt);
125  this.com_phys_friction_air = false;
126  this.com_phys_ladder = false;
127  this.com_phys_gravity = 0;
128  } else if (ITEMS_STAT(this) & IT_USING_JETPACK) {
129  PM_jetpack(this, maxspeed_mod, dt);
130  } else if (IS_ONGROUND(this) && (!IS_ONSLICK(this) || !PHYS_SLICK_APPLYGRAVITY(this))) {
131  if (!WAS_ONGROUND(this)) {
132  emit(phys_land, this);
133  if (this.lastground < time - 0.3) {
134  this.velocity *= (1 - PHYS_FRICTION_ONLAND(this));
135  }
136  }
137  this.com_phys_vel_max = PHYS_MAXSPEED(this) * maxspeed_mod;
138  this.com_phys_gravity = -PHYS_GRAVITY(this) * dt;
139  if (PHYS_ENTGRAVITY(this)) { this.com_phys_gravity *= PHYS_ENTGRAVITY(this); }
140  this.com_phys_ground = true;
141  this.com_phys_vel_2d = true;
142  sys_phys_simulate(this, dt);
143  this.com_phys_vel_2d = false;
144  this.com_phys_ground = false;
145  this.com_phys_gravity = 0;
146  } else {
147  this.com_phys_acc_rate_air = PHYS_AIRACCELERATE(this) * min(maxspeed_mod, 1);
148  this.com_phys_acc_rate_air_stop = PHYS_AIRSTOPACCELERATE(this) * maxspeed_mod;
149  this.com_phys_acc_rate_air_strafe = PHYS_AIRSTRAFEACCELERATE(this) * maxspeed_mod;
150  this.com_phys_vel_max_air_strafe = PHYS_MAXAIRSTRAFESPEED(this) * maxspeed_mod;
151  this.com_phys_vel_max_air = PHYS_MAXAIRSPEED(this) * maxspeed_mod;
152  this.com_phys_vel_max = PHYS_MAXAIRSPEED(this) * min(maxspeed_mod, 1);
153  this.com_phys_air = true;
154  this.com_phys_vel_2d = true;
155  sys_phys_simulate(this, dt);
156  this.com_phys_vel_2d = false;
157  this.com_phys_air = false;
158  }
159 
160  sys_phys_postupdate(this);
161 }
float MOVETYPE_NONE
Definition: progsdefs.qc:246
void CheckPlayerJump(entity this)
Definition: player.qc:473
#define PHYS_MAXAIRSPEED(s)
Definition: player.qh:130
const float CONTENT_LAVA
Definition: csprogsdefs.qc:240
#define WAS_ONGROUND(s)
Definition: player.qh:203
#define PHYS_ACCELERATE(s)
Definition: player.qh:91
float waterlevel
Definition: progsdefs.qc:181
#define IS_CLIENT(v)
Definition: utils.qh:13
bool sys_phys_override(entity this, float dt)
Definition: cl_physics.qc:13
void sys_phys_simulate(entity this, float dt)
for players
Definition: physics.qc:174
float teleport_time
Definition: player.qh:212
#define PHYS_FRICTION(s)
Definition: player.qh:110
void PM_check_slick(entity this)
Definition: player.qc:670
bool move_qcphysics
Definition: physics.qh:25
void PM_check_hitground(entity this)
Definition: player.qc:624
void sys_phys_postupdate(entity this)
Definition: physics.qc:163
bool com_phys_ladder
Definition: physics.qh:21
float com_phys_acc_rate_air_strafe
Definition: physics.qh:12
float com_phys_acc_rate_air
Definition: physics.qh:11
vector v_angle
Definition: progsdefs.qc:161
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
#define PHYS_INPUT_BUTTON_MASK(s)
Definition: player.qh:185
float lastground
Definition: player.qh:61
void sys_phys_fixspeed(entity this, float maxspeed_mod)
Definition: cl_physics.qc:27
float jumppadcount
Definition: jumppads.qh:15
bool com_phys_ground
Definition: physics.qh:19
bool wasFlying
Definition: player.qh:62
float com_phys_acc_rate_air_stop
Definition: physics.qh:13
#define PHYS_SLICK_APPLYGRAVITY(s)
Definition: player.qh:144
#define ITEMS_STAT(s)
Definition: player.qh:210
float move_movetype
Definition: movetypes.qh:76
float com_phys_vel_max_air
Definition: physics.qh:8
void sys_phys_simulate_simple(entity this, float dt)
for other entities
Definition: physics.qc:423
const int WATERLEVEL_NONE
Definition: movetypes.qh:11
void viewloc_PlayerPhysics(entity this)
Definition: viewloc.qc:13
float com_phys_vel_max_air_strafe
Definition: physics.qh:9
vector absmax
Definition: csprogsdefs.qc:92
#define PHYS_AIRSTOPACCELERATE(s)
Definition: player.qh:102
vector movedir
Definition: progsdefs.qc:203
void PM_Footsteps(entity this)
Definition: player.qc:649
const float CONTENT_SLIME
Definition: csprogsdefs.qc:239
entity conveyor
Definition: player.qh:54
const float CONTENT_WATER
Definition: csprogsdefs.qc:238
void PM_check_frozen(entity this)
Definition: player.qc:609
#define PHYS_AIRACCELERATE(s)
Definition: player.qh:92
float MOVETYPE_FLY_WORLDONLY
#define IS_ONSLICK(s)
Definition: movetypes.qh:19
float com_phys_friction
Definition: physics.qh:14
void sys_phys_ai(entity this)
Definition: cl_physics.qc:21
void PM_jetpack(entity this, float maxspd_mod, float dt)
Definition: player.qc:695
void PM_check_blocked(entity this)
Definition: player.qc:683
#define IS_DEAD(s)
Definition: utils.qh:26
void sys_phys_pregame_hold(entity this)
Definition: cl_physics.qc:23
bool IsFlying(entity this)
Definition: player.qc:804
float com_phys_acc_rate
Definition: physics.qh:10
entity ladder_entity
Definition: ladder.qh:11
#define IS_SVQC
Definition: _all.inc:14
vector(float skel, float bonenum) _skel_get_boneabs_hidden
bool com_phys_air
Definition: physics.qh:20
float com_phys_vel_max
Definition: physics.qh:7
float MOVETYPE_NOCLIP
Definition: progsdefs.qc:254
float flags
Definition: csprogsdefs.qc:129
float MOVETYPE_FOLLOW
bool com_phys_water
Definition: physics.qh:23
bool com_phys_vel_2d
Definition: physics.qh:22
const int WATERLEVEL_SWIMMING
Definition: movetypes.qh:13
void sys_in_update(entity this, float dt)
Definition: input.qc:3
float com_phys_gravity
Definition: physics.qh:16
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
#define PHYS_MAXAIRSTRAFESPEED(s)
Definition: player.qh:131
#define emit(T,...)
Definition: lib.qh:17
void sys_phys_fix(entity this, float dt)
Definition: cl_physics.qc:3
vector angles
Definition: csprogsdefs.qc:104
vector absmin
Definition: csprogsdefs.qc:92
#define PHYS_AIRSTRAFEACCELERATE(s)
Definition: player.qh:103
float time
Definition: csprogsdefs.qc:16
void sys_phys_monitor(entity this, float dt)
Definition: cl_physics.qc:19
vector velocity
Definition: csprogsdefs.qc:103
#define PHYS_MAXSPEED(s)
Definition: player.qh:132
float MOVETYPE_FLY
Definition: progsdefs.qc:251
#define IS_PLAYER(v)
Definition: utils.qh:9
float FL_WATERJUMP
Definition: progsdefs.qc:242
int disableclientprediction
Definition: physics.qc:4
bool com_phys_friction_air
Definition: physics.qh:24
#define PHYS_FRICTION_ONLAND(s)
Definition: player.qh:111
void sys_phys_spectator_control(entity this)
Definition: cl_physics.qc:25
+ Here is the caller graph for this function:

Variable Documentation

◆ jetpack_stopped

float jetpack_stopped

Definition at line 472 of file player.qc.

Referenced by CheckPlayerJump().