1 #include "cl_client.qh"
3 #include "anticheat.qh"
4 #include "cl_impulse.qh"
5 #include "cl_player.qh"
7 #include "miscfunctions.qh"
10 #include "playerdemo.qh"
11 #include "spawnpoints.qh"
12 #include "g_damage.qh"
14 #include "command/common.qh"
19 #include "campaign.qh"
20 #include "command/common.qh"
23 #include "bot/navigation.qh"
25 #include "../common/ent_cs.qh"
26 #include <common/state.qh>
28 #include <common/effects/qc/globalsound.qh>
30 #include "../common/triggers/teleporters.qh"
32 #include "../common/vehicles/all.qh"
34 #include "weapons/hitplot.qh"
35 #include "weapons/weaponsystem.qh"
37 #include "../common/net_notice.qh"
38 #include "../common/physics/player.qh"
40 #include "../common/items/all.qc"
42 #include "../common/mutators/mutator/waypoints/all.qh"
44 #include "../common/triggers/subs.qh"
45 #include "../common/triggers/triggers.qh"
46 #include "../common/triggers/trigger/secret.qh"
48 #include "../common/minigames/sv_minigames.qh"
50 #include "../common/items/inventory.qh"
52 #include "../common/monsters/sv_monsters.qh"
54 #include "../lib/warpzone/server.qh"
57 void send_CSQC_teamnagger() {
58 WriteHeader(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
61 bool ClientData_Send(entity this, entity to, int sf)
63 assert(to == this.owner, return false);
66 if (IS_SPEC(e)) e = e.enemy;
69 if (e.race_completed) sf |= 1; // forced scoreboard
70 if (to.spectatee_status) sf |= 2; // spectator ent number follows
71 if (e.zoomstate) sf |= 4; // zoomed
72 if (e.porto_v_angle_held) sf |= 8; // angles held
74 WriteHeader(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
75 WriteByte(MSG_ENTITY, sf);
79 WriteByte(MSG_ENTITY, to.spectatee_status);
83 WriteAngle(MSG_ENTITY, e.v_angle.x);
84 WriteAngle(MSG_ENTITY, e.v_angle.y);
89 void ClientData_Attach(entity this)
91 Net_LinkEntity(this.clientdata = new_pure(clientdata), false, 0, ClientData_Send);
92 self.clientdata.drawonlytoclient = this;
93 self.clientdata.owner = this;
96 void ClientData_Detach(entity this)
98 remove(this.clientdata);
99 self.clientdata = NULL;
102 void ClientData_Touch(entity e)
104 e.clientdata.SendFlags = 1;
106 // make it spectatable
107 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != e && IS_SPEC(it) && it.enemy == e, LAMBDA(it.clientdata.SendFlags = 1));
110 .string netname_previous;
112 void SetSpectatee(entity player, entity spectatee);
119 Checks if the argument string can be a valid playermodel.
120 Returns a valid one in doubt.
123 string FallbackPlayerModel;
124 string CheckPlayerModel(string plyermodel) {
125 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
127 // note: we cannot summon Don Strunzone here, some player may
128 // still have the model string set. In case anyone manages how
129 // to change a cvar default, we'll have a small leak here.
130 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
132 // only in right path
133 if( substring(plyermodel,0,14) != "models/player/")
134 return FallbackPlayerModel;
135 // only good file extensions
136 if(substring(plyermodel,-4,4) != ".zym")
137 if(substring(plyermodel,-4,4) != ".dpm")
138 if(substring(plyermodel,-4,4) != ".iqm")
139 if(substring(plyermodel,-4,4) != ".md3")
140 if(substring(plyermodel,-4,4) != ".psk")
141 return FallbackPlayerModel;
142 // forbid the LOD models
143 if(substring(plyermodel, -9,5) == "_lod1")
144 return FallbackPlayerModel;
145 if(substring(plyermodel, -9,5) == "_lod2")
146 return FallbackPlayerModel;
147 if(plyermodel != strtolower(plyermodel))
148 return FallbackPlayerModel;
149 // also, restrict to server models
150 if(autocvar_sv_servermodelsonly)
152 if(!fexists(plyermodel))
153 return FallbackPlayerModel;
158 void setplayermodel(entity e, string modelname)
160 precache_model(modelname);
161 _setmodel(e, modelname);
162 player_setupanimsformodel();
163 if(!autocvar_g_debug_globalsounds)
164 UpdatePlayerSounds(e);
167 void FixPlayermodel(entity player);
168 /** putting a client as observer in the server */
169 void PutObserverInServer()
172 bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver);
173 PlayerState_detach(this);
175 if (IS_PLAYER(this) && this.health >= 1) {
177 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
181 entity spot = SelectSpawnPoint(true);
182 if (!spot) LOG_FATAL("No spawnpoints for observers?!?");
183 this.angles = spot.angles;
185 this.fixangle = true;
186 // offset it so that the spectator spawns higher off the ground, looks better this way
187 setorigin(this, spot.origin + STAT(PL_VIEW_OFS, NULL));
188 this.prevorigin = this.origin;
189 if (IS_REAL_CLIENT(this))
192 WriteByte(MSG_ONE, SVC_SETVIEW);
193 WriteEntity(MSG_ONE, this);
195 // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
196 // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
197 if(!autocvar_g_debug_globalsounds)
199 // needed for player sounds
201 FixPlayermodel(this);
203 setmodel(this, MDL_Null);
204 setsize(this, STAT(PL_CROUCH_MIN, NULL), STAT(PL_CROUCH_MAX, NULL));
205 this.view_ofs = '0 0 0';
208 RemoveGrapplingHook(this);
209 Portal_ClearAll(this);
215 PS_GR_P_ADDVAL(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
219 if (this.vehicle) vehicles_exit(VHEF_RELEASE);
221 WaypointSprite_PlayerDead(this);
223 if (mutator_returnvalue) {
224 // mutator prevents resetting teams+score
226 this.team = -1; // move this as it is needed to log the player spectating in eventlog
227 this.frags = FRAGS_SPECTATOR;
228 PlayerScore_Clear(this); // clear scores when needed
231 if (this.killcount != FRAGS_SPECTATOR)
233 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_SPECTATE, this.netname);
234 if(!intermission_running)
235 if(autocvar_g_chat_nospectators == 1 || (!(warmup_stage || gameover) && autocvar_g_chat_nospectators == 2))
236 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CHAT_NOSPECTATORS);
238 if(this.just_joined == false) {
239 LogTeamchange(this.playerid, -1, 4);
241 this.just_joined = false;
244 accuracy_resend(this);
246 this.spectatortime = time;
247 this.bot_attack = false;
248 this.hud = HUD_NORMAL;
249 this.classname = STR_OBSERVER;
250 this.iscreature = false;
251 this.teleportable = TELEPORT_SIMPLE;
252 this.damagedbycontents = false;
253 this.health = FRAGS_SPECTATOR;
254 this.takedamage = DAMAGE_NO;
255 this.solid = SOLID_NOT;
256 this.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink
257 this.flags = FL_CLIENT | FL_NOTARGET;
258 this.armorvalue = 666;
260 this.armorvalue = autocvar_g_balance_armor_start;
261 this.pauserotarmor_finished = 0;
262 this.pauserothealth_finished = 0;
263 this.pauseregen_finished = 0;
264 this.damageforcescale = 0;
266 this.respawn_flags = 0;
267 this.respawn_time = 0;
268 this.stat_respawn_time = 0;
273 this.pain_finished = 0;
274 this.strength_finished = 0;
275 this.invincible_finished = 0;
276 this.superweapons_finished = 0;
279 this.think = func_null;
282 this.deadflag = DEAD_NO;
284 this.revival_time = 0;
287 this.weapons = '0 0 0';
288 this.drawonlytoclient = this;
290 this.weaponname = "";
291 this.weaponmodel = "";
292 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
294 this.weaponentities[slot] = NULL;
296 this.exteriorweaponentity = NULL;
297 this.killcount = FRAGS_SPECTATOR;
298 this.velocity = '0 0 0';
299 this.avelocity = '0 0 0';
300 this.punchangle = '0 0 0';
301 this.punchvector = '0 0 0';
302 this.oldvelocity = this.velocity;
303 this.fire_endtime = -1;
304 this.event_damage = func_null;
307 int player_getspecies(entity this)
309 get_model_parameters(this.model, this.skin);
310 int s = get_model_parameters_species;
311 get_model_parameters(string_null, 0);
312 if (s < 0) return SPECIES_HUMAN;
316 .float model_randomizer;
317 void FixPlayermodel(entity player)
319 string defaultmodel = "";
321 if(autocvar_sv_defaultcharacter)
325 string s = Static_Team_ColorName_Lower(player.team);
328 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
329 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
333 if(defaultmodel == "")
335 defaultmodel = autocvar_sv_defaultplayermodel;
336 defaultskin = autocvar_sv_defaultplayerskin;
339 int n = tokenize_console(defaultmodel);
342 defaultmodel = argv(floor(n * player.model_randomizer));
343 // However, do NOT randomize if the player-selected model is in the list.
344 for (int i = 0; i < n; ++i)
345 if ((argv(i) == player.playermodel && defaultskin == stof(player.playerskin)) || argv(i) == strcat(player.playermodel, ":", player.playerskin))
346 defaultmodel = argv(i);
349 int i = strstrofs(defaultmodel, ":", 0);
352 defaultskin = stof(substring(defaultmodel, i+1, -1));
353 defaultmodel = substring(defaultmodel, 0, i);
356 MUTATOR_CALLHOOK(FixPlayermodel, defaultmodel, defaultskin);
357 defaultmodel = ret_string;
358 defaultskin = ret_int;
362 if(defaultmodel != "")
364 if (defaultmodel != player.model)
366 vector m1 = player.mins;
367 vector m2 = player.maxs;
368 setplayermodel (player, defaultmodel);
369 setsize (player, m1, m2);
373 oldskin = player.skin;
374 player.skin = defaultskin;
376 if (player.playermodel != player.model || player.playermodel == "")
378 player.playermodel = CheckPlayerModel(player.playermodel); // this is never "", so no endless loop
379 vector m1 = player.mins;
380 vector m2 = player.maxs;
381 setplayermodel (player, player.playermodel);
382 setsize (player, m1, m2);
386 oldskin = player.skin;
387 player.skin = stof(player.playerskin);
390 if(chmdl || oldskin != player.skin) // model or skin has changed
392 player.species = player_getspecies(player); // update species
393 if(!autocvar_g_debug_globalsounds)
394 UpdatePlayerSounds(player); // update skin sounds
398 if(strlen(autocvar_sv_defaultplayercolors))
399 if(player.clientcolors != stof(autocvar_sv_defaultplayercolors))
400 setcolor(player, stof(autocvar_sv_defaultplayercolors));
404 /** Called when a client spawns in the server */
405 void PutClientInServer()
408 if (IS_BOT_CLIENT(this)) {
409 this.classname = STR_PLAYER;
410 } else if (IS_REAL_CLIENT(this)) {
412 WriteByte(MSG_ONE, SVC_SETVIEW);
413 WriteEntity(MSG_ONE, this);
416 this.classname = STR_OBSERVER;
419 SetSpectatee(this, NULL);
424 MUTATOR_CALLHOOK(PutClientInServer, this);
426 if (IS_OBSERVER(this)) {
427 PutObserverInServer();
428 } else if (IS_PLAYER(this)) {
429 PlayerState_attach(this);
430 accuracy_resend(this);
433 JoinBestTeam(this, false, true);
435 entity spot = SelectSpawnPoint(false);
437 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
438 return; // spawn failed
441 this.classname = STR_PLAYER;
442 this.wasplayer = true;
443 this.iscreature = true;
444 this.teleportable = TELEPORT_NORMAL;
445 this.damagedbycontents = true;
446 this.movetype = MOVETYPE_WALK;
447 this.solid = SOLID_SLIDEBOX;
448 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
449 if (autocvar_g_playerclip_collisions)
450 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
451 if (IS_BOT_CLIENT(this) && autocvar_g_botclip_collisions)
452 this.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
453 this.frags = FRAGS_PLAYER;
454 if (INDEPENDENT_PLAYERS) MAKE_INDEPENDENT_PLAYER(this);
455 this.flags = FL_CLIENT | FL_PICKUPITEMS;
456 if (autocvar__notarget)
457 this.flags |= FL_NOTARGET;
458 this.takedamage = DAMAGE_AIM;
459 this.effects = EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
463 this.ammo_shells = warmup_start_ammo_shells;
464 this.ammo_nails = warmup_start_ammo_nails;
465 this.ammo_rockets = warmup_start_ammo_rockets;
466 this.ammo_cells = warmup_start_ammo_cells;
467 this.ammo_plasma = warmup_start_ammo_plasma;
468 this.ammo_fuel = warmup_start_ammo_fuel;
469 this.health = warmup_start_health;
470 this.armorvalue = warmup_start_armorvalue;
471 this.weapons = WARMUP_START_WEAPONS;
473 this.ammo_shells = start_ammo_shells;
474 this.ammo_nails = start_ammo_nails;
475 this.ammo_rockets = start_ammo_rockets;
476 this.ammo_cells = start_ammo_cells;
477 this.ammo_plasma = start_ammo_plasma;
478 this.ammo_fuel = start_ammo_fuel;
479 this.health = start_health;
480 this.armorvalue = start_armorvalue;
481 this.weapons = start_weapons;
484 this.superweapons_finished = (this.weapons & WEPSET_SUPERWEAPONS) ? time + autocvar_g_balance_superweapons_time : 0;
486 this.items = start_items;
488 this.spawnshieldtime = time + autocvar_g_spawnshieldtime;
489 this.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
490 this.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
491 this.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
492 this.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
493 // extend the pause of rotting if client was reset at the beginning of the countdown
494 if (!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
495 float f = game_starttime - time;
496 this.spawnshieldtime += f;
497 this.pauserotarmor_finished += f;
498 this.pauserothealth_finished += f;
499 this.pauseregen_finished += f;
501 this.damageforcescale = 2;
503 this.respawn_flags = 0;
504 this.respawn_time = 0;
505 this.stat_respawn_time = 0;
506 this.scale = autocvar_sv_player_scale;
509 this.pain_finished = 0;
511 this.think = func_null; // players have no think function
514 this.ballistics_density = autocvar_g_ballistics_density_player;
516 this.deadflag = DEAD_NO;
518 this.angles = spot.angles;
519 this.angles_z = 0; // never spawn tilted even if the spot says to
520 if (IS_BOT_CLIENT(this))
521 this.v_angle = this.angles;
522 this.fixangle = true; // turn this way immediately
523 this.oldvelocity = this.velocity = '0 0 0';
524 this.avelocity = '0 0 0';
525 this.punchangle = '0 0 0';
526 this.punchvector = '0 0 0';
528 this.strength_finished = 0;
529 this.invincible_finished = 0;
530 this.fire_endtime = -1;
531 this.revival_time = 0;
532 this.air_finished = time + 12;
534 entity spawnevent = new_pure(spawnevent);
535 spawnevent.owner = this;
536 Net_LinkEntity(spawnevent, false, 0.5, SpawnEvent_Send);
538 // Cut off any still running player sounds.
539 stopsound(this, CH_PLAYER_SINGLE);
542 FixPlayermodel(this);
543 this.drawonlytoclient = NULL;
546 this.view_ofs = STAT(PL_VIEW_OFS, NULL);
547 setsize(this, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
548 this.spawnorigin = spot.origin;
549 setorigin(this, spot.origin + '0 0 1' * (1 - this.mins.z - 24));
550 // don't reset back to last position, even if new position is stuck in solid
551 this.oldorigin = this.origin;
552 this.prevorigin = this.origin;
553 this.lastteleporttime = time; // prevent insane speeds due to changing origin
554 this.hud = HUD_NORMAL;
556 this.event_damage = PlayerDamage;
558 this.bot_attack = true;
559 this.monster_attack = true;
561 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_JUMP(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
563 if (this.killcount == FRAGS_SPECTATOR) {
564 PlayerScore_Clear(this);
568 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
570 CL_SpawnWeaponentity(this, weaponentities[slot]);
572 this.alpha = default_player_alpha;
573 this.colormod = '1 1 1' * autocvar_g_player_brightness;
574 this.exteriorweaponentity.alpha = default_weapon_alpha;
576 this.speedrunning = false;
578 target_voicescript_clear(this);
580 // reset fields the weapons may use
581 FOREACH(Weapons, true, LAMBDA(
582 it.wr_resetplayer(it);
583 // reload all reloadable weapons
584 if (it.spawnflags & WEP_FLAG_RELOADABLE) {
585 this.weapon_load[it.m_id] = it.reloading_ammo;
590 string s = spot.target;
591 spot.target = string_null;
592 WITH(entity, activator, this, LAMBDA(
593 WITH(entity, self, spot, SUB_UseTargets())
600 MUTATOR_CALLHOOK(PlayerSpawn, spot);
602 if (autocvar_spawn_debug)
604 sprint(this, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
605 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
608 PS(this).m_switchweapon = w_getbestweapon(this);
609 this.cnt = -1; // W_LastWeapon will not complain
610 PS(this).m_weapon = WEP_Null;
611 this.weaponname = "";
612 PS(this).m_switchingweapon = WEP_Null;
614 if (!warmup_stage && !this.alivetime)
615 this.alivetime = time;
617 antilag_clear(this, CS(this));
621 void ClientInit_misc();
623 .float ebouncefactor, ebouncestop; // electro's values
624 // TODO do we need all these fields, or should we stop autodetecting runtime
625 // changes and just have a console command to update this?
626 bool ClientInit_SendEntity(entity this, entity to, int sf)
628 WriteHeader(MSG_ENTITY, _ENT_CLIENT_INIT);
631 // MSG_INIT replacement
632 // TODO: make easier to use
634 W_PROP_reload(MSG_ONE, to);
636 MUTATOR_CALLHOOK(Ent_Init);
638 void ClientInit_misc()
641 int channel = MSG_ONE;
642 WriteHeader(channel, ENT_CLIENT_INIT);
643 WriteByte(channel, g_nexball_meter_period * 32);
644 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[0]));
645 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[1]));
646 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[2]));
647 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[3]));
648 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[0]));
649 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[1]));
650 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[2]));
651 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[3]));
653 if(sv_foginterval && world.fog != "")
654 WriteString(channel, world.fog);
656 WriteString(channel, "");
657 WriteByte(channel, self.count * 255.0); // g_balance_armor_blockpercent
658 WriteByte(channel, serverflags); // client has to know if it should zoom or not
659 WriteCoord(channel, autocvar_g_trueaim_minrange);
662 void ClientInit_CheckUpdate()
664 self.nextthink = time;
665 if(self.count != autocvar_g_balance_armor_blockpercent)
667 self.count = autocvar_g_balance_armor_blockpercent;
672 void ClientInit_Spawn()
675 entity e = new_pure(clientinit);
676 e.think = ClientInit_CheckUpdate;
677 Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
679 WITH(entity, self, e, ClientInit_CheckUpdate());
689 // initialize parms for a new player
690 parm1 = -(86400 * 366);
692 MUTATOR_CALLHOOK(SetNewParms);
700 void SetChangeParms ()
702 // save parms for level change
703 parm1 = self.parm_idlesince - time;
705 MUTATOR_CALLHOOK(SetChangeParms);
713 void DecodeLevelParms(entity this)
716 this.parm_idlesince = parm1;
717 if (this.parm_idlesince == -(86400 * 366))
718 this.parm_idlesince = time;
720 // whatever happens, allow 60 seconds of idling directly after connect for map loading
721 this.parm_idlesince = max(this.parm_idlesince, time - sv_maxidle + 60);
723 MUTATOR_CALLHOOK(DecodeLevelParms);
730 Called when a client types 'kill' in the console
734 .float clientkill_nexttime;
735 void ClientKill_Now_TeamChange(entity this)
737 if(this.killindicator_teamchange == -1)
739 JoinBestTeam( this, false, true );
741 else if(this.killindicator_teamchange == -2)
744 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
745 WITH(entity, self, this, PutObserverInServer());
748 WITH(entity, self, this, SV_ChangeTeam(this.killindicator_teamchange - 1));
749 this.killindicator_teamchange = 0;
752 void ClientKill_Now()
756 vehicles_exit(VHEF_RELEASE);
757 if(!self.killindicator_teamchange)
759 self.vehicle_health = -1;
760 Damage(self, self, self, 1 , DEATH_KILL.m_id, self.origin, '0 0 0');
764 if(self.killindicator && !wasfreed(self.killindicator))
765 remove(self.killindicator);
767 self.killindicator = world;
769 if(self.killindicator_teamchange)
770 ClientKill_Now_TeamChange(self);
773 Damage(self, self, self, 100000, DEATH_KILL.m_id, self.origin, '0 0 0');
775 // now I am sure the player IS dead
777 void KillIndicator_Think()
781 self.owner.killindicator = world;
786 if (self.owner.alpha < 0 && !self.owner.vehicle)
788 self.owner.killindicator = world;
795 WITH(entity, self, self.owner, ClientKill_Now());
798 else if(g_cts && self.health == 1) // health == 1 means that it's silent
800 self.nextthink = time + 1;
806 setmodel(self, MDL_NUM(self.cnt));
807 if(IS_REAL_CLIENT(self.owner))
810 { Send_Notification(NOTIF_ONE, self.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, self.cnt)); }
812 self.nextthink = time + 1;
817 float clientkilltime;
818 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
827 killtime = autocvar_g_balance_kill_delay;
829 if(g_race_qualifying || g_cts)
832 if(MUTATOR_CALLHOOK(ClientKill, self, killtime))
835 self.killindicator_teamchange = targetteam;
837 if(!self.killindicator)
841 killtime = max(killtime, self.clientkill_nexttime - time);
842 self.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
845 if(killtime <= 0 || !IS_PLAYER(self) || IS_DEAD(self))
851 starttime = max(time, clientkilltime);
853 self.killindicator = spawn();
854 self.killindicator.owner = self;
855 self.killindicator.scale = 0.5;
856 setattachment(self.killindicator, self, "");
857 setorigin(self.killindicator, '0 0 52');
858 self.killindicator.think = KillIndicator_Think;
859 self.killindicator.nextthink = starttime + (self.lip) * 0.05;
860 clientkilltime = max(clientkilltime, self.killindicator.nextthink + 0.05);
861 self.killindicator.cnt = ceil(killtime);
862 self.killindicator.count = bound(0, ceil(killtime), 10);
863 //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
865 for(e = world; (e = find(e, classname, "body")) != world; )
869 e.killindicator = spawn();
870 e.killindicator.owner = e;
871 e.killindicator.scale = 0.5;
872 setattachment(e.killindicator, e, "");
873 setorigin(e.killindicator, '0 0 52');
874 e.killindicator.think = KillIndicator_Think;
875 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
876 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
877 e.killindicator.cnt = ceil(killtime);
882 if(self.killindicator)
884 if(targetteam == 0) // just die
886 self.killindicator.colormod = '0 0 0';
887 if(IS_REAL_CLIENT(self))
888 if(self.killindicator.cnt > 0)
889 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, self.killindicator.cnt);
891 else if(targetteam == -1) // auto
893 self.killindicator.colormod = '0 1 0';
894 if(IS_REAL_CLIENT(self))
895 if(self.killindicator.cnt > 0)
896 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, self.killindicator.cnt);
898 else if(targetteam == -2) // spectate
900 self.killindicator.colormod = '0.5 0.5 0.5';
901 if(IS_REAL_CLIENT(self))
902 if(self.killindicator.cnt > 0)
903 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, self.killindicator.cnt);
907 self.killindicator.colormod = Team_ColorRGB(targetteam);
908 if(IS_REAL_CLIENT(self))
909 if(self.killindicator.cnt > 0)
910 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE), self.killindicator.cnt);
919 if(self.player_blocked) return;
920 if(STAT(FROZEN, self)) return;
922 ClientKill_TeamChange(0);
925 void FixClientCvars(entity e)
927 // send prediction settings to the client
928 stuffcmd(e, "\nin_bindmap 0 0\n");
929 if(autocvar_g_antilag == 3) // client side hitscan
930 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
931 if(autocvar_sv_gentle)
932 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
934 MUTATOR_CALLHOOK(FixClientCvars, e);
937 float PlayerInIDList(entity p, string idlist)
942 // NOTE: we do NOT check crypto_idfp_signed here, an unsigned ID is fine too for this
946 // this function allows abbreviated player IDs too!
947 n = tokenize_console(idlist);
948 for(i = 0; i < n; ++i)
951 if(s == substring(p.crypto_idfp, 0, strlen(s)))
958 #ifdef DP_EXT_PRECONNECT
963 Called once (not at each match start) when a client begins a connection to the server
966 void ClientPreConnect ()
968 if(autocvar_sv_eventlog)
970 GameLogEcho(sprintf(":connect:%d:%d:%s",
973 ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot")
983 Called when a client connects to the server
989 if (Ban_MaybeEnforceBanOnce(this)) return;
990 assert(!IS_CLIENT(this), return);
991 assert(player_count >= 0, player_count = 0);
992 this.classname = "player_joining";
993 this.flags = FL_CLIENT;
996 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_WATERMARK, WATERMARK);
998 this.version_nagtime = time + 10 + random() * 10;
1000 ClientState_attach(this);
1002 // identify the right forced team
1003 if (autocvar_g_campaign)
1005 if (IS_REAL_CLIENT(this)) // only players, not bots
1007 switch (autocvar_g_campaign_forceteam)
1009 case 1: this.team_forced = NUM_TEAM_1; break;
1010 case 2: this.team_forced = NUM_TEAM_2; break;
1011 case 3: this.team_forced = NUM_TEAM_3; break;
1012 case 4: this.team_forced = NUM_TEAM_4; break;
1013 default: this.team_forced = 0;
1017 else if (PlayerInIDList(this, autocvar_g_forced_team_red)) this.team_forced = NUM_TEAM_1;
1018 else if (PlayerInIDList(this, autocvar_g_forced_team_blue)) this.team_forced = NUM_TEAM_2;
1019 else if (PlayerInIDList(this, autocvar_g_forced_team_yellow)) this.team_forced = NUM_TEAM_3;
1020 else if (PlayerInIDList(this, autocvar_g_forced_team_pink)) this.team_forced = NUM_TEAM_4;
1021 else switch (autocvar_g_forced_team_otherwise)
1023 default: this.team_forced = 0; break;
1024 case "red": this.team_forced = NUM_TEAM_1; break;
1025 case "blue": this.team_forced = NUM_TEAM_2; break;
1026 case "yellow": this.team_forced = NUM_TEAM_3; break;
1027 case "pink": this.team_forced = NUM_TEAM_4; break;
1030 this.team_forced = -1;
1033 if (!teamplay && this.team_forced > 0) this.team_forced = 0;
1035 JoinBestTeam(this, false, false); // if the team number is valid, keep it
1037 if (autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) {
1038 this.classname = STR_OBSERVER;
1040 if (!teamplay || autocvar_g_balance_teams)
1042 this.classname = STR_PLAYER;
1043 campaign_bots_may_start = 1;
1047 this.classname = STR_OBSERVER; // do it anyway
1051 this.playerid = ++playerid_last;
1053 PlayerStats_GameReport_AddEvent(sprintf("kills-%d", this.playerid));
1055 // always track bots, don't ask for cl_allow_uidtracking
1056 if (IS_BOT_CLIENT(this)) PlayerStats_GameReport_AddPlayer(this);
1058 if (autocvar_sv_eventlog)
1059 GameLogEcho(strcat(":join:", ftos(this.playerid), ":", ftos(etof(this)), ":", ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot"), ":", this.netname));
1061 LogTeamchange(this.playerid, this.team, 1);
1063 this.just_joined = true; // stop spamming the eventlog with additional lines when the client connects
1065 this.netname_previous = strzone(this.netname);
1067 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && IS_PLAYER(this)) ? APP_TEAM_ENT(this, INFO_JOIN_CONNECT_TEAM) : INFO_JOIN_CONNECT), this.netname);
1069 stuffcmd(this, clientstuff, "\n");
1070 stuffcmd(this, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1072 FixClientCvars(this);
1074 // get version info from player
1075 stuffcmd(this, "cmd clientversion $gameversion\n");
1077 // notify about available teams
1080 CheckAllowedTeams(this);
1082 if (c1 >= 0) t |= BIT(0);
1083 if (c2 >= 0) t |= BIT(1);
1084 if (c3 >= 0) t |= BIT(2);
1085 if (c4 >= 0) t |= BIT(3);
1086 stuffcmd(this, sprintf("set _teams_available %d\n", t));
1090 stuffcmd(this, "set _teams_available 0\n");
1093 bot_relinkplayerlist();
1095 this.spectatortime = time;
1096 if (blockSpectators)
1098 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1101 this.jointime = time;
1102 this.allowed_timeouts = autocvar_sv_timeout_number;
1104 if (IS_REAL_CLIENT(this))
1106 if (!autocvar_g_campaign)
1108 this.motd_actived_time = -1;
1109 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1112 if (g_weaponarena_weapons == WEPSET(TUBA))
1113 stuffcmd(this, "cl_cmd settemp chase_active 1\n");
1116 if (!sv_foginterval && world.fog != "")
1117 stuffcmd(this, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1119 if (autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)))
1120 if (!g_ca && !g_cts && !g_race) // teamnagger is currently bad for ca, race & cts
1121 send_CSQC_teamnagger();
1123 CSQCMODEL_AUTOINIT(this);
1125 this.model_randomizer = random();
1127 if (IS_REAL_CLIENT(this))
1128 sv_notice_join(this);
1130 FOREACH_ENTITY_FLOAT(init_for_player_needed, true, {
1131 WITH(entity, self, it, it.init_for_player(it));
1134 MUTATOR_CALLHOOK(ClientConnect, this);
1140 Called when a client disconnects from the server
1143 .entity chatbubbleentity;
1145 void ClientDisconnect()
1148 assert(IS_CLIENT(this), return);
1150 PlayerStats_GameReport_FinalizePlayer(this);
1151 if (this.vehicle) vehicles_exit(VHEF_RELEASE);
1152 if (this.active_minigame) part_minigame(this);
1153 if (IS_PLAYER(this)) Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
1155 if (autocvar_sv_eventlog)
1156 GameLogEcho(strcat(":part:", ftos(this.playerid)));
1158 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
1160 MUTATOR_CALLHOOK(ClientDisconnect);
1162 ClientState_detach(this);
1164 Portal_ClearAll(self);
1168 RemoveGrapplingHook(self);
1170 // Here, everything has been done that requires this player to be a client.
1172 self.flags &= ~FL_CLIENT;
1174 if (this.chatbubbleentity) remove(this.chatbubbleentity);
1175 if (this.killindicator) remove(this.killindicator);
1177 WaypointSprite_PlayerGone();
1179 bot_relinkplayerlist();
1181 if (self.netname_previous) strunzone(self.netname_previous);
1182 if (self.clientstatus) strunzone(self.clientstatus);
1183 if (self.weaponorder_byimpulse) strunzone(self.weaponorder_byimpulse);
1184 if (self.personal) remove(self.personal);
1188 if (vote_called && IS_REAL_CLIENT(this)) VoteCount(false);
1191 void ChatBubbleThink()
1193 self.nextthink = time;
1194 if ((self.owner.alpha < 0) || self.owner.chatbubbleentity != self)
1196 if(self.owner) // but why can that ever be world?
1197 self.owner.chatbubbleentity = world;
1204 if ( !IS_DEAD(self.owner) && IS_PLAYER(self.owner) )
1206 if ( self.owner.active_minigame )
1207 self.mdl = "models/sprites/minigame_busy.iqm";
1208 else if (PHYS_INPUT_BUTTON_CHAT(self.owner))
1209 self.mdl = "models/misc/chatbubble.spr";
1212 if ( self.model != self.mdl )
1213 _setmodel(self, self.mdl);
1217 void UpdateChatBubble()
1221 // spawn a chatbubble entity if needed
1222 if (!self.chatbubbleentity)
1224 self.chatbubbleentity = new(chatbubbleentity);
1225 self.chatbubbleentity.owner = self;
1226 self.chatbubbleentity.exteriormodeltoclient = self;
1227 self.chatbubbleentity.think = ChatBubbleThink;
1228 self.chatbubbleentity.nextthink = time;
1229 setmodel(self.chatbubbleentity, MDL_CHAT); // precision set below
1230 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1231 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1232 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1233 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1234 //self.chatbubbleentity.model = "";
1235 self.chatbubbleentity.effects = EF_LOWPRECISION;
1240 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1241 // added to the model skins
1242 /*void UpdateColorModHack()
1245 c = self.clientcolors & 15;
1246 // LordHavoc: only bothering to support white, green, red, yellow, blue
1247 if (!teamplay) self.colormod = '0 0 0';
1248 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1249 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1250 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1251 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1252 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1253 else self.colormod = '1 1 1';
1258 if(self.alpha >= 0 && autocvar_g_respawn_ghosts)
1260 self.solid = SOLID_NOT;
1261 self.takedamage = DAMAGE_NO;
1262 self.movetype = MOVETYPE_FLY;
1263 self.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1264 self.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1265 self.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1266 Send_Effect(EFFECT_RESPAWN_GHOST, self.origin, '0 0 0', 1);
1267 if(autocvar_g_respawn_ghosts_maxtime)
1268 SUB_SetFade (self, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1273 self.effects |= EF_NODRAW; // prevent another CopyBody
1274 PutClientInServer();
1277 void play_countdown(float finished, Sound samp)
1280 if(IS_REAL_CLIENT(self))
1281 if(floor(finished - time - frametime) != floor(finished - time))
1282 if(finished - time < 6)
1283 sound (self, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
1286 void player_powerups ()
1288 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1289 int items_prev = self.items;
1291 if((self.items & IT_USING_JETPACK) && !IS_DEAD(self) && !gameover)
1292 self.modelflags |= MF_ROCKET;
1294 self.modelflags &= ~MF_ROCKET;
1296 self.effects &= ~(EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1298 if((self.alpha < 0 || IS_DEAD(self)) && !self.vehicle) // don't apply the flags if the player is gibbed
1301 Fire_ApplyDamage(self);
1302 Fire_ApplyEffect(self);
1306 if (self.items & ITEM_Strength.m_itemid)
1308 play_countdown(self.strength_finished, SND_POWEROFF);
1309 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1310 if (time > self.strength_finished)
1312 self.items = self.items - (self.items & ITEM_Strength.m_itemid);
1313 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, self.netname);
1314 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
1319 if (time < self.strength_finished)
1321 self.items = self.items | ITEM_Strength.m_itemid;
1322 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, self.netname);
1323 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_STRENGTH);
1326 if (self.items & ITEM_Shield.m_itemid)
1328 play_countdown(self.invincible_finished, SND_POWEROFF);
1329 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1330 if (time > self.invincible_finished)
1332 self.items = self.items - (self.items & ITEM_Shield.m_itemid);
1333 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, self.netname);
1334 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
1339 if (time < self.invincible_finished)
1341 self.items = self.items | ITEM_Shield.m_itemid;
1342 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, self.netname);
1343 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SHIELD);
1346 if (self.items & IT_SUPERWEAPON)
1348 if (!(self.weapons & WEPSET_SUPERWEAPONS))
1350 self.superweapons_finished = 0;
1351 self.items = self.items - (self.items & IT_SUPERWEAPON);
1352 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, self.netname);
1353 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1355 else if (self.items & IT_UNLIMITED_SUPERWEAPONS)
1357 // don't let them run out
1361 play_countdown(self.superweapons_finished, SND_POWEROFF);
1362 if (time > self.superweapons_finished)
1364 self.items = self.items - (self.items & IT_SUPERWEAPON);
1365 self.weapons &= ~WEPSET_SUPERWEAPONS;
1366 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, self.netname);
1367 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1371 else if(self.weapons & WEPSET_SUPERWEAPONS)
1373 if (time < self.superweapons_finished || (self.items & IT_UNLIMITED_SUPERWEAPONS))
1375 self.items = self.items | IT_SUPERWEAPON;
1376 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, self.netname);
1377 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1381 self.superweapons_finished = 0;
1382 self.weapons &= ~WEPSET_SUPERWEAPONS;
1387 self.superweapons_finished = 0;
1391 if(autocvar_g_nodepthtestplayers)
1392 self.effects = self.effects | EF_NODEPTHTEST;
1394 if(autocvar_g_fullbrightplayers)
1395 self.effects = self.effects | EF_FULLBRIGHT;
1397 if (time >= game_starttime)
1398 if (time < self.spawnshieldtime)
1399 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1401 MUTATOR_CALLHOOK(PlayerPowerups, self, items_prev);
1404 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1406 if(current > stable)
1408 else if(current > stable - 0.25) // when close enough, "snap"
1411 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1414 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1416 if(current < stable)
1418 else if(current < stable + 0.25) // when close enough, "snap"
1421 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1424 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1426 if(current > rotstable)
1428 if(rotframetime > 0)
1430 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1431 current = max(rotstable, current - rotlinear * rotframetime);
1434 else if(current < regenstable)
1436 if(regenframetime > 0)
1438 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1439 current = min(regenstable, current + regenlinear * regenframetime);
1449 void player_regen ()
1451 float max_mod, regen_mod, rot_mod, limit_mod;
1452 max_mod = regen_mod = rot_mod = limit_mod = 1;
1453 regen_mod_max = max_mod;
1454 regen_mod_regen = regen_mod;
1455 regen_mod_rot = rot_mod;
1456 regen_mod_limit = limit_mod;
1458 regen_health = autocvar_g_balance_health_regen;
1459 regen_health_linear = autocvar_g_balance_health_regenlinear;
1460 regen_health_rot = autocvar_g_balance_health_rot;
1461 regen_health_rotlinear = autocvar_g_balance_health_rotlinear;
1462 regen_health_stable = autocvar_g_balance_health_regenstable;
1463 regen_health_rotstable = autocvar_g_balance_health_rotstable;
1464 if(!MUTATOR_CALLHOOK(PlayerRegen))
1465 if(!STAT(FROZEN, self))
1467 float mina, maxa, limith, limita;
1468 maxa = autocvar_g_balance_armor_rotstable;
1469 mina = autocvar_g_balance_armor_regenstable;
1470 limith = autocvar_g_balance_health_limit;
1471 limita = autocvar_g_balance_armor_limit;
1473 max_mod = regen_mod_max;
1474 regen_mod = regen_mod_regen;
1475 rot_mod = regen_mod_rot;
1476 limit_mod = regen_mod_limit;
1478 regen_health_rotstable = regen_health_rotstable * max_mod;
1479 regen_health_stable = regen_health_stable * max_mod;
1480 limith = limith * limit_mod;
1481 limita = limita * limit_mod;
1483 self.armorvalue = CalcRotRegen(self.armorvalue, mina, autocvar_g_balance_armor_regen, autocvar_g_balance_armor_regenlinear, regen_mod * frametime * (time > self.pauseregen_finished), maxa, autocvar_g_balance_armor_rot, autocvar_g_balance_armor_rotlinear, rot_mod * frametime * (time > self.pauserotarmor_finished), limita);
1484 self.health = CalcRotRegen(self.health, regen_health_stable, regen_health, regen_health_linear, regen_mod * frametime * (time > self.pauseregen_finished), regen_health_rotstable, regen_health_rot, regen_health_rotlinear, rot_mod * frametime * (time > self.pauserothealth_finished), limith);
1487 // if player rotted to death... die!
1488 // check this outside above checks, as player may still be able to rot to death
1492 vehicles_exit(VHEF_RELEASE);
1493 if(self.event_damage)
1494 self.event_damage(self, self, self, 1, DEATH_ROT.m_id, self.origin, '0 0 0');
1497 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
1499 float minf, maxf, limitf;
1501 maxf = autocvar_g_balance_fuel_rotstable;
1502 minf = autocvar_g_balance_fuel_regenstable;
1503 limitf = autocvar_g_balance_fuel_limit;
1505 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, frametime * (time > self.pauseregen_finished) * ((self.items & ITEM_JetpackRegen.m_itemid) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > self.pauserotfuel_finished), limitf);
1509 float zoomstate_set;
1510 void SetZoomState(float z)
1512 if(z != self.zoomstate)
1515 ClientData_Touch(self);
1520 void GetPressedKeys()
1523 MUTATOR_CALLHOOK(GetPressedKeys);
1524 int keys = this.pressedkeys;
1525 keys = BITSET(keys, KEY_FORWARD, this.movement.x > 0);
1526 keys = BITSET(keys, KEY_BACKWARD, this.movement.x < 0);
1527 keys = BITSET(keys, KEY_RIGHT, this.movement.y > 0);
1528 keys = BITSET(keys, KEY_LEFT, this.movement.y < 0);
1530 keys = BITSET(keys, KEY_JUMP, PHYS_INPUT_BUTTON_JUMP(this));
1531 keys = BITSET(keys, KEY_CROUCH, PHYS_INPUT_BUTTON_CROUCH(this));
1532 keys = BITSET(keys, KEY_ATCK, PHYS_INPUT_BUTTON_ATCK(this));
1533 keys = BITSET(keys, KEY_ATCK2, PHYS_INPUT_BUTTON_ATCK2(this));
1534 this.pressedkeys = keys;
1538 ======================
1539 spectate mode routines
1540 ======================
1543 void SpectateCopy(entity this, entity spectatee)
1545 TC(Client, this); TC(Client, spectatee);
1547 MUTATOR_CALLHOOK(SpectateCopy, spectatee, this);
1548 PS(this) = PS(spectatee);
1549 this.armortype = spectatee.armortype;
1550 this.armorvalue = spectatee.armorvalue;
1551 this.ammo_cells = spectatee.ammo_cells;
1552 this.ammo_plasma = spectatee.ammo_plasma;
1553 this.ammo_shells = spectatee.ammo_shells;
1554 this.ammo_nails = spectatee.ammo_nails;
1555 this.ammo_rockets = spectatee.ammo_rockets;
1556 this.ammo_fuel = spectatee.ammo_fuel;
1557 this.clip_load = spectatee.clip_load;
1558 this.clip_size = spectatee.clip_size;
1559 this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1560 this.health = spectatee.health;
1562 this.items = spectatee.items;
1563 this.last_pickup = spectatee.last_pickup;
1564 this.hit_time = spectatee.hit_time;
1565 this.strength_finished = spectatee.strength_finished;
1566 this.invincible_finished = spectatee.invincible_finished;
1567 this.pressedkeys = spectatee.pressedkeys;
1568 this.weapons = spectatee.weapons;
1569 this.vortex_charge = spectatee.vortex_charge;
1570 this.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
1571 this.hagar_load = spectatee.hagar_load;
1572 this.arc_heat_percent = spectatee.arc_heat_percent;
1573 this.minelayer_mines = spectatee.minelayer_mines;
1574 this.punchangle = spectatee.punchangle;
1575 this.view_ofs = spectatee.view_ofs;
1576 this.velocity = spectatee.velocity;
1577 this.dmg_take = spectatee.dmg_take;
1578 this.dmg_save = spectatee.dmg_save;
1579 this.dmg_inflictor = spectatee.dmg_inflictor;
1580 this.v_angle = spectatee.v_angle;
1581 this.angles = spectatee.v_angle;
1582 STAT(FROZEN, this) = STAT(FROZEN, spectatee);
1583 this.revive_progress = spectatee.revive_progress;
1584 if(!PHYS_INPUT_BUTTON_USE(this))
1585 this.fixangle = true;
1586 setorigin(this, spectatee.origin);
1587 setsize(this, spectatee.mins, spectatee.maxs);
1588 SetZoomState(spectatee.zoomstate);
1590 anticheat_spectatecopy(this, spectatee);
1591 this.hud = spectatee.hud;
1592 if(spectatee.vehicle)
1594 this.fixangle = false;
1595 //this.velocity = spectatee.vehicle.velocity;
1596 this.vehicle_health = spectatee.vehicle_health;
1597 this.vehicle_shield = spectatee.vehicle_shield;
1598 this.vehicle_energy = spectatee.vehicle_energy;
1599 this.vehicle_ammo1 = spectatee.vehicle_ammo1;
1600 this.vehicle_ammo2 = spectatee.vehicle_ammo2;
1601 this.vehicle_reload1 = spectatee.vehicle_reload1;
1602 this.vehicle_reload2 = spectatee.vehicle_reload2;
1606 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1607 WriteAngle(MSG_ONE, spectatee.v_angle.x);
1608 WriteAngle(MSG_ONE, spectatee.v_angle.y);
1609 WriteAngle(MSG_ONE, spectatee.v_angle.z);
1611 //WriteByte (MSG_ONE, SVC_SETVIEW);
1612 // WriteEntity(MSG_ONE, this);
1613 //makevectors(spectatee.v_angle);
1614 //setorigin(this, spectatee.origin - v_forward * 400 + v_up * 300);*/
1618 bool SpectateUpdate()
1623 if(!IS_PLAYER(self.enemy) || self == self.enemy)
1625 SetSpectatee(self, NULL);
1629 SpectateCopy(this, this.enemy);
1636 if(!IS_PLAYER(self.enemy))
1640 WriteByte(MSG_ONE, SVC_SETVIEW);
1641 WriteEntity(MSG_ONE, self.enemy);
1642 self.movetype = MOVETYPE_NONE;
1643 accuracy_resend(self);
1645 if(!SpectateUpdate())
1646 PutObserverInServer();
1651 void SetSpectatee(entity player, entity spectatee)
1653 entity old_spectatee = player.enemy;
1655 player.enemy = spectatee;
1658 // these are required to fix the spectator bug with arc
1659 if(old_spectatee && old_spectatee.arc_beam) { old_spectatee.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1660 if(player.enemy && player.enemy.arc_beam) { player.enemy.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1663 bool Spectate(entity pl)
1665 if(MUTATOR_CALLHOOK(SpectateSet, self, pl))
1669 SetSpectatee(self, pl);
1670 return SpectateSet();
1675 other = find(self.enemy, classname, STR_PLAYER);
1677 if (MUTATOR_CALLHOOK(SpectateNext, self, other))
1678 other = spec_player;
1680 other = find(other, classname, STR_PLAYER);
1682 if(other) { SetSpectatee(self, other); }
1684 return SpectateSet();
1689 // NOTE: chain order is from the highest to the lower entnum (unlike find)
1690 other = findchain(classname, STR_PLAYER);
1691 if (!other) // no player
1694 entity first = other;
1695 // skip players until current spectated player
1697 while(other && other != self.enemy)
1698 other = other.chain;
1700 switch (MUTATOR_CALLHOOK(SpectatePrev, self, other, first))
1702 case MUT_SPECPREV_FOUND:
1703 other = spec_player;
1705 case MUT_SPECPREV_RETURN:
1706 other = spec_player;
1708 case MUT_SPECPREV_CONTINUE:
1712 other = other.chain;
1719 SetSpectatee(self, other);
1720 return SpectateSet();
1725 ShowRespawnCountdown()
1727 Update a respawn countdown display.
1730 void ShowRespawnCountdown()
1733 if(!IS_DEAD(self)) // just respawned?
1737 number = ceil(self.respawn_time - time);
1740 if(number <= self.respawn_countdown)
1742 self.respawn_countdown = number - 1;
1743 if(ceil(self.respawn_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
1744 { Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(CNT_RESPAWN, number)); }
1749 void LeaveSpectatorMode()
1753 if(nJoinAllowed(self, self))
1755 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0)
1757 self.classname = STR_PLAYER;
1759 if(autocvar_g_campaign || autocvar_g_balance_teams)
1760 { JoinBestTeam(self, false, true); }
1762 if(autocvar_g_campaign)
1763 { campaign_bots_may_start = 1; }
1765 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_PREVENT_JOIN);
1767 PutClientInServer();
1769 if(IS_PLAYER(self)) { Send_Notification(NOTIF_ALL, world, MSG_INFO, ((teamplay && this.team != -1) ? APP_TEAM_ENT(this, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), self.netname); }
1772 stuffcmd(self, "menu_showteamselect\n");
1776 // Player may not join because g_maxplayers is set
1777 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_JOIN_PREVENT);
1782 * Determines whether the player is allowed to join. This depends on cvar
1783 * g_maxplayers, if it isn't used this function always return true, otherwise
1784 * it checks whether the number of currently playing players exceeds g_maxplayers.
1785 * @return int number of free slots for players, 0 if none
1787 bool nJoinAllowed(entity this, entity ignore)
1790 // this is called that way when checking if anyone may be able to join (to build qcstatus)
1791 // so report 0 free slots if restricted
1793 if(autocvar_g_forced_team_otherwise == "spectate")
1795 if(autocvar_g_forced_team_otherwise == "spectator")
1799 if(this.team_forced < 0)
1800 return false; // forced spectators can never join
1802 // TODO simplify this
1803 int totalClients = 0;
1804 int currentlyPlaying = 0;
1805 FOREACH_CLIENT(true, LAMBDA(
1808 if(IS_REAL_CLIENT(it))
1809 if(IS_PLAYER(it) || it.caplayer)
1813 if (!autocvar_g_maxplayers)
1814 return maxclients - totalClients;
1816 if(currentlyPlaying < autocvar_g_maxplayers)
1817 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
1823 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1824 * g_maxplayers_spectator_blocktime seconds
1826 void checkSpectatorBlock()
1828 if(IS_SPEC(self) || IS_OBSERVER(self))
1830 if(IS_REAL_CLIENT(self))
1832 if( time > (self.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
1833 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
1839 void PrintWelcomeMessage()
1841 if(self.motd_actived_time == 0)
1843 if (autocvar_g_campaign) {
1844 if ((IS_PLAYER(self) && PHYS_INPUT_BUTTON_INFO(self)) || (!IS_PLAYER(self))) {
1845 self.motd_actived_time = time;
1846 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, campaign_message);
1849 if (PHYS_INPUT_BUTTON_INFO(self)) {
1850 self.motd_actived_time = time;
1851 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1855 else if(self.motd_actived_time > 0) // showing MOTD or campaign message
1857 if (autocvar_g_campaign) {
1858 if (PHYS_INPUT_BUTTON_INFO(self))
1859 self.motd_actived_time = time;
1860 else if ((time - self.motd_actived_time > 2) && IS_PLAYER(self)) { // hide it some seconds after BUTTON_INFO has been released
1861 self.motd_actived_time = 0;
1862 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_MOTD);
1865 if (PHYS_INPUT_BUTTON_INFO(self))
1866 self.motd_actived_time = time;
1867 else if (time - self.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
1868 self.motd_actived_time = 0;
1869 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_MOTD);
1873 else //if(self.motd_actived_time < 0) // just connected, motd is active
1875 if(PHYS_INPUT_BUTTON_INFO(self)) // BUTTON_INFO hides initial MOTD
1876 self.motd_actived_time = -2; // wait until BUTTON_INFO gets released
1877 else if(self.motd_actived_time == -2 || IS_PLAYER(self) || IS_SPEC(self))
1879 // instanctly hide MOTD
1880 self.motd_actived_time = 0;
1881 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_MOTD);
1886 void ObserverThink()
1890 MinigameImpulse(self, self.impulse);
1893 float prefered_movetype;
1894 if (self.flags & FL_JUMPRELEASED) {
1895 if (PHYS_INPUT_BUTTON_JUMP(self) && !self.version_mismatch) {
1896 self.flags &= ~FL_JUMPRELEASED;
1897 self.flags |= FL_SPAWNING;
1898 } else if(PHYS_INPUT_BUTTON_ATCK(self) && !self.version_mismatch) {
1899 self.flags &= ~FL_JUMPRELEASED;
1900 if(SpectateNext()) {
1901 self.classname = STR_SPECTATOR;
1904 prefered_movetype = ((!PHYS_INPUT_BUTTON_USE(self) ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
1905 if (self.movetype != prefered_movetype)
1906 self.movetype = prefered_movetype;
1909 if (!(PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_JUMP(self))) {
1910 self.flags |= FL_JUMPRELEASED;
1911 if(self.flags & FL_SPAWNING)
1913 self.flags &= ~FL_SPAWNING;
1914 LeaveSpectatorMode();
1921 void SpectatorThink()
1925 if(MinigameImpulse(self, self.impulse))
1928 if (self.flags & FL_JUMPRELEASED) {
1929 if (PHYS_INPUT_BUTTON_JUMP(self) && !self.version_mismatch) {
1930 self.flags &= ~FL_JUMPRELEASED;
1931 self.flags |= FL_SPAWNING;
1932 } else if(PHYS_INPUT_BUTTON_ATCK(self) || self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209)) {
1933 self.flags &= ~FL_JUMPRELEASED;
1934 if(SpectateNext()) {
1935 self.classname = STR_SPECTATOR;
1937 self.classname = STR_OBSERVER;
1938 PutClientInServer();
1941 } else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229)) {
1942 self.flags &= ~FL_JUMPRELEASED;
1943 if(SpectatePrev()) {
1944 self.classname = STR_SPECTATOR;
1946 self.classname = STR_OBSERVER;
1947 PutClientInServer();
1950 } else if (PHYS_INPUT_BUTTON_ATCK2(self)) {
1951 self.flags &= ~FL_JUMPRELEASED;
1952 self.classname = STR_OBSERVER;
1953 PutClientInServer();
1955 if(!SpectateUpdate())
1956 PutObserverInServer();
1959 if (!(PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_ATCK2(self))) {
1960 self.flags |= FL_JUMPRELEASED;
1961 if(self.flags & FL_SPAWNING)
1963 self.flags &= ~FL_SPAWNING;
1964 LeaveSpectatorMode();
1968 if(!SpectateUpdate())
1969 PutObserverInServer();
1972 self.flags |= FL_CLIENT | FL_NOTARGET;
1975 void vehicles_enter (entity pl, entity veh);
1978 if (!IS_PLAYER(self))
1985 vehicles_exit(VHEF_NORMAL);
1989 else if(autocvar_g_vehicles_enter)
1991 if(!STAT(FROZEN, self))
1995 entity head, closest_target = world;
1996 head = WarpZone_FindRadius(self.origin, autocvar_g_vehicles_enter_radius, true);
1998 while(head) // find the closest acceptable target to enter
2000 if(head.vehicle_flags & VHF_ISVEHICLE)
2002 if(!head.owner || ((head.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(head.owner, self)))
2003 if(head.takedamage != DAMAGE_NO)
2007 if(vlen(self.origin - head.origin) < vlen(self.origin - closest_target.origin))
2008 { closest_target = head; }
2010 else { closest_target = head; }
2016 if(closest_target) { vehicles_enter(self, closest_target); return; }
2020 // a use key was pressed; call handlers
2021 MUTATOR_CALLHOOK(PlayerUseKey);
2029 Called every frame for each client before the physics are run
2032 .float usekeypressed;
2033 void() nexball_setstatus;
2034 .float last_vehiclecheck;
2036 void PlayerPreThink ()
2038 WarpZone_PlayerPhysics_FixVAngle();
2040 self.stat_game_starttime = game_starttime;
2041 self.stat_round_starttime = round_starttime;
2042 self.stat_allow_oldvortexbeam = autocvar_g_allow_oldvortexbeam;
2043 self.stat_leadlimit = autocvar_leadlimit;
2045 self.weaponsinmap = weaponsInMap;
2049 // physics frames: update anticheat stuff
2050 anticheat_prethink(self);
2053 if(blockSpectators && frametime)
2054 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2055 checkSpectatorBlock();
2059 // Savage: Check for nameless players
2060 if (isInvisibleString(self.netname)) {
2061 string new_name = strzone(strcat("Player@", ftos(self.playerid)));
2062 if(autocvar_sv_eventlog)
2063 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", new_name));
2064 if(self.netname_previous)
2065 strunzone(self.netname_previous);
2066 self.netname_previous = strzone(new_name);
2067 self.netname = self.netname_previous;
2068 // stuffcmd(self, strcat("name ", self.netname, "\n"));
2069 } else if(self.netname_previous != self.netname) {
2070 if(autocvar_sv_eventlog)
2071 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2072 if(self.netname_previous)
2073 strunzone(self.netname_previous);
2074 self.netname_previous = strzone(self.netname);
2078 if(self.version_nagtime)
2079 if(self.cvar_g_xonoticversion)
2080 if(time > self.version_nagtime)
2082 // don't notify git users
2083 if(strstrofs(self.cvar_g_xonoticversion, "git", 0) < 0 && strstrofs(self.cvar_g_xonoticversion, "autobuild", 0) < 0)
2085 if(strstrofs(autocvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(autocvar_g_xonoticversion, "autobuild", 0) >= 0)
2087 // notify release users if connecting to git
2088 LOG_TRACE("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", autocvar_g_xonoticversion, " (beta)^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2089 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2094 r = vercmp(self.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2097 // give users new version
2098 LOG_TRACE("^1NOTE^7 to ", self.netname, "^7 - ^3Xonotic ", autocvar_g_xonoticversion, "^7 is out, and you still have ^3Xonotic ", self.cvar_g_xonoticversion, "^1 - get the update from ^4http://www.xonotic.org/^1!\n");
2099 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2103 // notify users about old server version
2104 LOG_INFO("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", autocvar_g_xonoticversion, "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2105 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2109 self.version_nagtime = 0;
2113 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2115 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_GODMODE_OFF, self.max_armorvalue);
2116 self.max_armorvalue = 0;
2119 if(STAT(FROZEN, self) == 2)
2121 self.revive_progress = bound(0, self.revive_progress + frametime * self.revive_speed, 1);
2122 self.health = max(1, self.revive_progress * start_health);
2123 self.iceblock.alpha = bound(0.2, 1 - self.revive_progress, 1);
2125 if(self.revive_progress >= 1)
2128 else if(STAT(FROZEN, self) == 3)
2130 self.revive_progress = bound(0, self.revive_progress - frametime * self.revive_speed, 1);
2131 self.health = max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * self.revive_progress );
2136 vehicles_exit(VHEF_RELEASE);
2137 self.event_damage(self, self, self.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, self.origin, '0 0 0');
2139 else if ( self.revive_progress <= 0 )
2143 MUTATOR_CALLHOOK(PlayerPreThink);
2145 if(autocvar_g_vehicles_enter)
2146 if(time > self.last_vehiclecheck)
2149 if(!STAT(FROZEN, self))
2154 for(veh = world; (veh = findflags(veh, vehicle_flags, VHF_ISVEHICLE)); )
2155 if(vlen(veh.origin - self.origin) < autocvar_g_vehicles_enter_radius)
2157 if(veh.takedamage != DAMAGE_NO)
2158 if((veh.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(veh.owner, self))
2159 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
2161 if(!veh.team || SAME_TEAM(self, veh))
2162 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER);
2163 else if(autocvar_g_vehicles_steal)
2164 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
2166 self.last_vehiclecheck = time + 1;
2169 if(!self.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2171 if(PHYS_INPUT_BUTTON_USE(self) && !self.usekeypressed)
2173 self.usekeypressed = PHYS_INPUT_BUTTON_USE(self);
2176 if(IS_REAL_CLIENT(self))
2177 PrintWelcomeMessage();
2182 CheckRules_Player();
2184 if (intermission_running)
2186 IntermissionThink (); // otherwise a button could be missed between
2187 return; // the think tics
2190 //don't allow the player to turn around while game is paused!
2191 if(timeout_status == TIMEOUT_ACTIVE) {
2192 // FIXME turn this into CSQC stuff
2193 self.v_angle = self.lastV_angle;
2194 self.angles = self.lastV_angle;
2195 self.fixangle = true;
2205 if(self.personal && g_race_qualifying)
2207 if(time > self.respawn_time)
2209 self.respawn_time = time + 1; // only retry once a second
2210 self.stat_respawn_time = self.respawn_time;
2217 float button_pressed;
2220 button_pressed = (PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_ATCK2(self) || PHYS_INPUT_BUTTON_HOOK(self) || PHYS_INPUT_BUTTON_USE(self));
2222 if (self.deadflag == DEAD_DYING)
2224 if((self.respawn_flags & RESPAWN_FORCE) && !autocvar_g_respawn_delay_max)
2225 self.deadflag = DEAD_RESPAWNING;
2226 else if(!button_pressed)
2227 self.deadflag = DEAD_DEAD;
2229 else if (self.deadflag == DEAD_DEAD)
2232 self.deadflag = DEAD_RESPAWNABLE;
2233 else if(time >= self.respawn_time_max && (self.respawn_flags & RESPAWN_FORCE))
2234 self.deadflag = DEAD_RESPAWNING;
2236 else if (self.deadflag == DEAD_RESPAWNABLE)
2239 self.deadflag = DEAD_RESPAWNING;
2241 else if (self.deadflag == DEAD_RESPAWNING)
2243 if(time > self.respawn_time)
2245 self.respawn_time = time + 1; // only retry once a second
2246 self.respawn_time_max = self.respawn_time;
2251 ShowRespawnCountdown();
2253 if(self.respawn_flags & RESPAWN_SILENT)
2254 self.stat_respawn_time = 0;
2255 else if((self.respawn_flags & RESPAWN_FORCE) && autocvar_g_respawn_delay_max)
2256 self.stat_respawn_time = self.respawn_time_max;
2258 self.stat_respawn_time = self.respawn_time;
2261 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2262 if(self.deadflag == DEAD_RESPAWNING && self.stat_respawn_time > 0)
2263 self.stat_respawn_time *= -1;
2268 self.prevorigin = self.origin;
2270 float do_crouch = PHYS_INPUT_BUTTON_CROUCH(self);
2275 if(STAT(FROZEN, self))
2278 // WEAPONTODO: THIS SHIT NEEDS TO GO EVENTUALLY
2279 // It cannot be predicted by the engine!
2280 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
2281 if((PS(self).m_weapon == WEP_SHOCKWAVE || PS(self).m_weapon == WEP_SHOTGUN) && self.(weaponentity).wframe == WFRAME_FIRE2 && time < self.(weaponentity).weapon_nextthink)
2289 self.view_ofs = STAT(PL_CROUCH_VIEW_OFS, self);
2290 setsize (self, STAT(PL_CROUCH_MIN, self), STAT(PL_CROUCH_MAX, self));
2291 // setanim(self, self.anim_duck, false, true, true); // this anim is BROKEN anyway
2298 tracebox(self.origin, STAT(PL_MIN, self), STAT(PL_MAX, self), self.origin, false, self);
2299 if (!trace_startsolid)
2301 self.crouch = false;
2302 self.view_ofs = STAT(PL_VIEW_OFS, self);
2303 setsize (self, STAT(PL_MIN, self), STAT(PL_MAX, self));
2308 FixPlayermodel(self);
2310 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2313 self.items &= ~self.items_added;
2315 W_WeaponFrame(self);
2317 self.items_added = 0;
2318 if(self.items & ITEM_Jetpack.m_itemid)
2319 if(self.items & ITEM_JetpackRegen.m_itemid || self.ammo_fuel >= 0.01)
2320 self.items_added |= IT_FUEL;
2322 self.items |= self.items_added;
2327 // WEAPONTODO: Add a weapon request for this
2328 // rot vortex charge to the charge limit
2329 if(WEP_CVAR(vortex, charge_rot_rate) && self.vortex_charge > WEP_CVAR(vortex, charge_limit) && self.vortex_charge_rottime < time)
2330 self.vortex_charge = bound(WEP_CVAR(vortex, charge_limit), self.vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1);
2336 secrets_setstatus();
2339 monsters_setstatus(self);
2341 self.dmg_team = max(0, self.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2343 //self.angles_y=self.v_angle_y + 90; // temp
2344 } else if(gameover) {
2345 if (intermission_running)
2346 IntermissionThink (); // otherwise a button could be missed between
2348 } else if(IS_OBSERVER(self)) {
2350 } else if(IS_SPEC(self)) {
2354 // WEAPONTODO: Add weapon request for this
2357 PHYS_INPUT_BUTTON_ZOOM(self)
2358 || PHYS_INPUT_BUTTON_ZOOMSCRIPT(self)
2359 || (PHYS_INPUT_BUTTON_ATCK2(self) && PS(self).m_weapon == WEP_VORTEX)
2360 || (PHYS_INPUT_BUTTON_ATCK2(self) && PS(self).m_weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0)
2363 float oldspectatee_status;
2364 oldspectatee_status = self.spectatee_status;
2366 self.spectatee_status = etof(self.enemy);
2367 else if(IS_OBSERVER(self))
2368 self.spectatee_status = etof(self);
2370 self.spectatee_status = 0;
2371 if(self.spectatee_status != oldspectatee_status)
2373 ClientData_Touch(self);
2375 race_InitSpectator();
2378 if(self.teamkill_soundtime)
2379 if(time > self.teamkill_soundtime)
2381 self.teamkill_soundtime = 0;
2383 entity e = self.teamkill_soundsource;
2384 entity oldpusher = e.pusher;
2386 PlayerSound(e, playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2387 e.pusher = oldpusher;
2390 if(self.taunt_soundtime)
2391 if(time > self.taunt_soundtime)
2393 self.taunt_soundtime = 0;
2394 PlayerSound(self, playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2397 target_voicescript_next(self);
2399 // WEAPONTODO: Move into weaponsystem somehow
2400 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2401 if (PS(self).m_weapon == WEP_Null)
2402 self.clip_load = self.clip_size = 0;
2405 void DrownPlayer(entity this)
2410 if (this.waterlevel != WATERLEVEL_SUBMERGED)
2412 if(this.air_finished < time)
2413 PlayerSound(this, playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
2414 this.air_finished = time + autocvar_g_balance_contents_drowndelay;
2417 else if (this.air_finished < time)
2419 if (this.pain_finished < time)
2421 Damage (this, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, this.origin, '0 0 0');
2422 this.pain_finished = time + 0.5;
2431 Called every frame for each client after the physics are run
2434 .float idlekick_lasttimeleft;
2435 void PlayerPostThink ()
2437 if(sv_maxidle > 0 && frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2438 if(IS_REAL_CLIENT(self))
2439 if(IS_PLAYER(self) || sv_maxidle_spectatorsareidle)
2441 if (time - self.parm_idlesince < 1) // instead of (time == self.parm_idlesince) to support sv_maxidle <= 10
2443 if(self.idlekick_lasttimeleft)
2445 self.idlekick_lasttimeleft = 0;
2446 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_IDLING);
2452 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2453 if(timeleft == min(10, sv_maxidle - 1)) // - 1 to support sv_maxidle <= 10
2455 if(!self.idlekick_lasttimeleft)
2456 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
2460 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_KICK_IDLING, self.netname);
2464 else if(timeleft <= 10)
2466 if(timeleft != self.idlekick_lasttimeleft)
2467 { Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(CNT_IDLE, timeleft)); }
2468 self.idlekick_lasttimeleft = timeleft;
2475 //CheckPlayerJump();
2477 if(IS_PLAYER(self)) {
2479 CheckRules_Player();
2482 ImpulseCommands(self);
2483 if (intermission_running)
2484 return; // intermission or finale
2490 for(i = 0; i < 1000; ++i)
2493 end = self.origin + '0 0 1024' + 512 * randomvec();
2494 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2495 if(trace_fraction < 1)
2496 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2498 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2504 if(self.waypointsprite_attachedforcarrier)
2505 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id));
2509 CSQCMODEL_AUTOUPDATE(self);