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
13
14bool sys_phys_override(entity this, float dt)
15{
16 int buttons = PHYS_INPUT_BUTTON_MASK(this);
17 float idlesince = CS(this).parm_idlesince;
18 CS(this).parm_idlesince = time; // in the case that physics are overridden
19 if (PM_check_specialcommand(this, buttons))
20 return true;
21 if (this.PlayerPhysplug && this.PlayerPhysplug(this, dt))
22 return true;
23 CS(this).parm_idlesince = idlesince;
24 return false;
25}
26
27void sys_phys_monitor(entity this, float dt)
28{
29 int buttons = PHYS_INPUT_BUTTON_MASK(this);
31
32 // always do this so active players don't get kicked if sv_maxidle* get enabled mid-match
33 if (!PHYS_INPUT_BUTTON_CHAT(this))
34 if (buttons != CS(this).buttons_old
35 || CS(this).movement != CS(this).movement_old
36 || this.v_angle != CS(this).v_angle_old)
37 CS(this).parm_idlesince = time;
38
39 PM_check_punch(this, dt);
40}
41
43{
44 if (!IS_BOT_CLIENT(this))
45 return;
46 bot_think(this);
47}
48
50{
51 if (!IS_PLAYER(this))
52 return;
53 const bool allowed_to_move = (time >= game_starttime && !game_stopped);
54 if (!allowed_to_move)
55 {
56 this.velocity = '0 0 0';
59 }
60 else if (this.disableclientprediction == 2)
61 {
62 if (this.move_movetype == MOVETYPE_NONE)
65 }
66}
67
69{
70 float maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
71 if (!STAT(SPECTATORSPEED, this))
72 STAT(SPECTATORSPEED, this) = maxspeed_mod;
73 if ((CS(this).impulse >= 1 && CS(this).impulse <= 19)
74 || (CS(this).impulse >= 200 && CS(this).impulse <= 209)
75 || (CS(this).impulse >= 220 && CS(this).impulse <= 229))
76 {
77 if (this.lastclassname != STR_PLAYER)
78 {
79 if (CS(this).impulse == 10
80 || CS(this).impulse == 15
81 || CS(this).impulse == 18
82 || (CS(this).impulse >= 200 && CS(this).impulse <= 209))
83 {
85 STAT(SPECTATORSPEED, this) + 0.5,
87 }
88 else if (CS(this).impulse == 11)
89 STAT(SPECTATORSPEED, this) = maxspeed_mod;
90 else if (CS(this).impulse == 12
91 || CS(this).impulse == 16
92 || CS(this).impulse == 19
93 || (CS(this).impulse >= 220 && CS(this).impulse <= 229))
94 {
96 STAT(SPECTATORSPEED, this) - 0.5,
98 }
99 else if (CS(this).impulse >= 1 && CS(this).impulse <= 9)
100 STAT(SPECTATORSPEED, this) = 1 + 0.5 * (CS(this).impulse - 1);
101 } // otherwise just clear
102 CS(this).impulse = 0;
103 }
104}
105
106void sys_phys_fixspeed(entity this, float maxspeed_mod)
107{
108 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
109 if (this.speed != spd)
110 {
111 this.speed = spd; // TODO: send this as a stat and set the below cvars on the client?
112 string temps = ftos(spd);
113 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
114 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
115 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
116 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
117 }
118
119 if (this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min)
120 {
121 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
122 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
123 }
124 if (this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max)
125 {
126 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
127 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
128 }
129}
130
132{
134 LOG_TRACEF("landing velocity: %v (abs: %f)", this.velocity, vlen(this.velocity));
135
136 if (this.jumppadcount > 1)
137 LOG_TRACEF("%dx jumppad combo", this.jumppadcount);
138
139 this.jumppadcount = 0;
140}
141
142STATIC_INIT(sys_phys)
143{
144 entity listener = new_pure(sys_phys);
145 subscribe(listener, phys_land, sys_phys_land);
146}
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:161
void PM_check_punch(entity this, float dt)
Definition player.qc:617
void Physics_UpdateStats(entity this)
Definition player.qc:44
bool PM_check_specialcommand(entity this, int buttons)
Definition player.qc:584
string autocvar_sv_jumpspeedcap_max
Definition player.qh:47
vector movement
Definition player.qh:229
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:159
vector v_angle
Definition player.qh:237
#define PHYS_MAXAIRSPEED(s)
Definition player.qh:134
bool autocvar_speedmeter
Definition player.qh:46
#define PHYS_MAXSPEED(s)
Definition player.qh:136
#define IS_PLAYER(s)
Definition player.qh:243
string autocvar_sv_jumpspeedcap_min
Definition player.qh:49
#define PHYS_INPUT_BUTTON_MASK(s)
Definition player.qh:189
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:14
float autocvar_sv_spectator_speed_multiplier_max
Definition sv_physics.qc:5
void sys_phys_monitor(entity this, float dt)
Definition sv_physics.qc:27
void sys_phys_land(entity this)
void sys_phys_ai(entity this)
Definition sv_physics.qc:42
void sys_phys_spectator_control(entity this)
Definition sv_physics.qc:68
void sys_phys_pregame_hold(entity this)
Definition sv_physics.qc:49
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