Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_physics.qc
Go to the documentation of this file.
1#include "physics.qh"
2
6
12
13bool sys_phys_override(entity this, float dt)
14{
15 int buttons = PHYS_INPUT_BUTTON_MASK(this);
16 float idlesince = CS(this).parm_idlesince;
17 CS(this).parm_idlesince = time; // in the case that physics are overridden
18 if (PM_check_specialcommand(this, buttons))
19 return true;
20 if (this.PlayerPhysplug && this.PlayerPhysplug(this, dt))
21 return true;
22 CS(this).parm_idlesince = idlesince;
23 return false;
24}
25
26void sys_phys_monitor(entity this, float dt)
27{
28 int buttons = PHYS_INPUT_BUTTON_MASK(this);
30
31 // always do this so active players don't get kicked if sv_maxidle* get enabled mid-match
32 if (!PHYS_INPUT_BUTTON_CHAT(this))
33 if (buttons != CS(this).buttons_old
34 || CS(this).movement != CS(this).movement_old
35 || this.v_angle != CS(this).v_angle_old)
36 CS(this).parm_idlesince = time;
37
38 PM_check_punch(this, dt);
39}
40
42{
43 if (!IS_BOT_CLIENT(this))
44 return;
45 bot_think(this);
46}
47
49{
50 if (!IS_PLAYER(this))
51 return;
52 const bool allowed_to_move = (time >= game_starttime && !game_stopped);
53 if (!allowed_to_move)
54 {
55 this.velocity = '0 0 0';
58 }
59 else if (this.disableclientprediction == 2)
60 {
61 if (this.move_movetype == MOVETYPE_NONE)
64 }
65}
66
68{
69 float maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
70 if (!STAT(SPECTATORSPEED, this))
71 STAT(SPECTATORSPEED, this) = maxspeed_mod;
72 if ((CS(this).impulse >= 1 && CS(this).impulse <= 19)
73 || (CS(this).impulse >= 200 && CS(this).impulse <= 209)
74 || (CS(this).impulse >= 220 && CS(this).impulse <= 229))
75 {
76 if (this.lastclassname != STR_PLAYER)
77 {
78 if (CS(this).impulse == 10
79 || CS(this).impulse == 15
80 || CS(this).impulse == 18
81 || (CS(this).impulse >= 200 && CS(this).impulse <= 209))
82 {
84 STAT(SPECTATORSPEED, this) + 0.5,
86 }
87 else if (CS(this).impulse == 11)
88 STAT(SPECTATORSPEED, this) = maxspeed_mod;
89 else if (CS(this).impulse == 12
90 || CS(this).impulse == 16
91 || CS(this).impulse == 19
92 || (CS(this).impulse >= 220 && CS(this).impulse <= 229))
93 {
95 STAT(SPECTATORSPEED, this) - 0.5,
97 }
98 else if (CS(this).impulse >= 1 && CS(this).impulse <= 9)
99 STAT(SPECTATORSPEED, this) = 1 + 0.5 * (CS(this).impulse - 1);
100 } // otherwise just clear
101 CS(this).impulse = 0;
102 }
103}
104
105void sys_phys_fixspeed(entity this, float maxspeed_mod)
106{
107 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
108 if (this.speed != spd)
109 {
110 this.speed = spd; // TODO: send this as a stat and set the below cvars on the client?
111 string temps = ftos(spd);
112 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
113 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
114 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
115 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
116 }
117}
118
120{
122 LOG_TRACEF("landing velocity: %v (abs: %f)", this.velocity, vlen(this.velocity));
123
124 if (this.jumppadcount > 1)
125 LOG_TRACEF("%dx jumppad combo", this.jumppadcount);
126
127 this.jumppadcount = 0;
128}
129
130STATIC_INIT(sys_phys)
131{
132 entity listener = new_pure(sys_phys);
133 subscribe(listener, phys_land, sys_phys_land);
134}
void anticheat_physics(entity this)
Definition anticheat.qc:67
void bot_think(entity this)
Definition bot.qc:62
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void PM_ClientMovement_UpdateStatus(entity this)
Definition player.qc:170
void PM_check_punch(entity this, float dt)
Definition player.qc:626
bool PM_check_specialcommand(entity this, int buttons)
Definition player.qc:593
vector movement
Definition player.qh:228
string lastclassname
Definition player.qh:70
vector v_angle_old
Definition player.qh:69
int buttons_old
Definition player.qh:67
vector movement_old
Definition player.qh:68
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition player.qh:161
vector v_angle
Definition player.qh:236
#define PHYS_MAXAIRSPEED(s)
Definition player.qh:136
bool autocvar_speedmeter
Definition player.qh:46
#define PHYS_MAXSPEED(s)
Definition player.qh:138
#define IS_PLAYER(s)
Definition player.qh:242
#define PHYS_INPUT_BUTTON_MASK(s)
Definition player.qh:191
float game_starttime
Definition stats.qh:82
float game_stopped
Definition stats.qh:81
vector velocity
float time
float disableclientprediction
float speed
Definition dynlight.qc:9
float jumppadcount
Definition jumppads.qh:28
#define STAT(...)
Definition stats.qh:82
#define subscribe(listener, T, fn)
Definition lib.qh:22
#define LOG_TRACEF(...)
Definition log.qh:77
float bound(float min, float value, float max)
float vlen(vector v)
string ftos(float f)
float max(float f,...)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_WALK
Definition movetypes.qh:132
const int MOVETYPE_NONE
Definition movetypes.qh:129
float move_movetype
Definition movetypes.qh:76
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
float impulse
Definition progsdefs.qc:158
#define stuffcmd(cl,...)
Definition progsdefs.qh:23
void WarpZone_PlayerPhysics_FixVAngle(entity this)
Definition server.qc:865
ClientState CS(Client this)
Definition state.qh:47
#define STATIC_INIT(func)
during worldspawn
Definition static.qh:32
bool sys_phys_override(entity this, float dt)
Definition sv_physics.qc:13
float autocvar_sv_spectator_speed_multiplier_max
Definition sv_physics.qc:5
void sys_phys_monitor(entity this, float dt)
Definition sv_physics.qc:26
void sys_phys_land(entity this)
void sys_phys_ai(entity this)
Definition sv_physics.qc:41
void sys_phys_spectator_control(entity this)
Definition sv_physics.qc:67
void sys_phys_pregame_hold(entity this)
Definition sv_physics.qc:48
void sys_phys_fixspeed(entity this, float maxspeed_mod)
float autocvar_sv_spectator_speed_multiplier
Definition sv_physics.qc:3
void sys_phys_fix(entity this, float dt)
Definition sv_physics.qc:7
float autocvar_sv_spectator_speed_multiplier_min
Definition sv_physics.qc:4
const string STR_PLAYER
Definition utils.qh:5
#define IS_BOT_CLIENT(v)
want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v))
Definition utils.qh:15