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"
56 STATIC_METHOD(Client, Add, void(Client this, int _team))
58 WITHSELF(this, ClientConnect());
59 TRANSMUTE(Player, this);
62 WITHSELF(this, PutClientInServer());
65 void PutObserverInServer();
66 void ClientDisconnect();
68 STATIC_METHOD(Client, Remove, void(Client this))
70 TRANSMUTE(Observer, this);
71 WITHSELF(this, PutClientInServer());
72 WITHSELF(this, ClientDisconnect());
75 void send_CSQC_teamnagger() {
76 WriteHeader(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
79 bool ClientData_Send(entity this, entity to, int sf)
81 assert(to == this.owner, return false);
84 if (IS_SPEC(e)) e = e.enemy;
87 if (e.race_completed) sf |= 1; // forced scoreboard
88 if (to.spectatee_status) sf |= 2; // spectator ent number follows
89 if (e.zoomstate) sf |= 4; // zoomed
90 if (e.porto_v_angle_held) sf |= 8; // angles held
92 WriteHeader(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
93 WriteByte(MSG_ENTITY, sf);
97 WriteByte(MSG_ENTITY, to.spectatee_status);
101 WriteAngle(MSG_ENTITY, e.v_angle.x);
102 WriteAngle(MSG_ENTITY, e.v_angle.y);
107 void ClientData_Attach(entity this)
109 Net_LinkEntity(this.clientdata = new_pure(clientdata), false, 0, ClientData_Send);
110 this.clientdata.drawonlytoclient = this;
111 this.clientdata.owner = this;
114 void ClientData_Detach(entity this)
116 remove(this.clientdata);
117 this.clientdata = NULL;
120 void ClientData_Touch(entity e)
122 e.clientdata.SendFlags = 1;
124 // make it spectatable
125 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != e && IS_SPEC(it) && it.enemy == e, LAMBDA(it.clientdata.SendFlags = 1));
128 .string netname_previous;
130 void SetSpectatee(entity player, entity spectatee);
137 Checks if the argument string can be a valid playermodel.
138 Returns a valid one in doubt.
141 string FallbackPlayerModel;
142 string CheckPlayerModel(string plyermodel) {
143 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
145 // note: we cannot summon Don Strunzone here, some player may
146 // still have the model string set. In case anyone manages how
147 // to change a cvar default, we'll have a small leak here.
148 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
150 // only in right path
151 if( substring(plyermodel,0,14) != "models/player/")
152 return FallbackPlayerModel;
153 // only good file extensions
154 if(substring(plyermodel,-4,4) != ".zym")
155 if(substring(plyermodel,-4,4) != ".dpm")
156 if(substring(plyermodel,-4,4) != ".iqm")
157 if(substring(plyermodel,-4,4) != ".md3")
158 if(substring(plyermodel,-4,4) != ".psk")
159 return FallbackPlayerModel;
160 // forbid the LOD models
161 if(substring(plyermodel, -9,5) == "_lod1")
162 return FallbackPlayerModel;
163 if(substring(plyermodel, -9,5) == "_lod2")
164 return FallbackPlayerModel;
165 if(plyermodel != strtolower(plyermodel))
166 return FallbackPlayerModel;
167 // also, restrict to server models
168 if(autocvar_sv_servermodelsonly)
170 if(!fexists(plyermodel))
171 return FallbackPlayerModel;
176 void setplayermodel(entity e, string modelname)
178 precache_model(modelname);
179 _setmodel(e, modelname);
180 player_setupanimsformodel();
181 if(!autocvar_g_debug_globalsounds)
182 UpdatePlayerSounds(e);
185 void FixPlayermodel(entity player);
186 /** putting a client as observer in the server */
187 void PutObserverInServer()
190 bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver);
191 PlayerState_detach(this);
193 if (IS_PLAYER(this) && this.health >= 1) {
195 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
199 entity spot = SelectSpawnPoint(true);
200 if (!spot) LOG_FATAL("No spawnpoints for observers?!?");
201 this.angles = spot.angles;
203 this.fixangle = true;
204 // offset it so that the spectator spawns higher off the ground, looks better this way
205 setorigin(this, spot.origin + STAT(PL_VIEW_OFS, NULL));
206 this.prevorigin = this.origin;
207 if (IS_REAL_CLIENT(this))
210 WriteByte(MSG_ONE, SVC_SETVIEW);
211 WriteEntity(MSG_ONE, this);
213 // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
214 // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
215 if(!autocvar_g_debug_globalsounds)
217 // needed for player sounds
219 FixPlayermodel(this);
221 setmodel(this, MDL_Null);
222 setsize(this, STAT(PL_CROUCH_MIN, NULL), STAT(PL_CROUCH_MAX, NULL));
223 this.view_ofs = '0 0 0';
226 RemoveGrapplingHook(this);
227 Portal_ClearAll(this);
233 PS_GR_P_ADDVAL(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
237 if (this.vehicle) vehicles_exit(VHEF_RELEASE);
239 WaypointSprite_PlayerDead(this);
241 if (mutator_returnvalue) {
242 // mutator prevents resetting teams+score
244 this.team = -1; // move this as it is needed to log the player spectating in eventlog
245 this.frags = FRAGS_SPECTATOR;
246 PlayerScore_Clear(this); // clear scores when needed
249 if (this.killcount != FRAGS_SPECTATOR)
251 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_SPECTATE, this.netname);
252 if(!intermission_running)
253 if(autocvar_g_chat_nospectators == 1 || (!(warmup_stage || gameover) && autocvar_g_chat_nospectators == 2))
254 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CHAT_NOSPECTATORS);
256 if(this.just_joined == false) {
257 LogTeamchange(this.playerid, -1, 4);
259 this.just_joined = false;
262 accuracy_resend(this);
264 this.spectatortime = time;
265 this.bot_attack = false;
266 this.hud = HUD_NORMAL;
267 TRANSMUTE(Observer, this);
268 this.iscreature = false;
269 this.teleportable = TELEPORT_SIMPLE;
270 this.damagedbycontents = false;
271 this.health = FRAGS_SPECTATOR;
272 this.takedamage = DAMAGE_NO;
273 this.solid = SOLID_NOT;
274 this.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink
275 this.flags = FL_CLIENT | FL_NOTARGET;
276 this.armorvalue = 666;
278 this.armorvalue = autocvar_g_balance_armor_start;
279 this.pauserotarmor_finished = 0;
280 this.pauserothealth_finished = 0;
281 this.pauseregen_finished = 0;
282 this.damageforcescale = 0;
284 this.respawn_flags = 0;
285 this.respawn_time = 0;
286 this.stat_respawn_time = 0;
291 this.pain_finished = 0;
292 this.strength_finished = 0;
293 this.invincible_finished = 0;
294 this.superweapons_finished = 0;
297 this.think = func_null;
300 this.deadflag = DEAD_NO;
302 this.revival_time = 0;
305 this.weapons = '0 0 0';
306 this.drawonlytoclient = this;
308 this.weaponname = "";
309 this.weaponmodel = "";
310 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
312 this.weaponentities[slot] = NULL;
314 this.exteriorweaponentity = NULL;
315 this.killcount = FRAGS_SPECTATOR;
316 this.velocity = '0 0 0';
317 this.avelocity = '0 0 0';
318 this.punchangle = '0 0 0';
319 this.punchvector = '0 0 0';
320 this.oldvelocity = this.velocity;
321 this.fire_endtime = -1;
322 this.event_damage = func_null;
325 int player_getspecies(entity this)
327 get_model_parameters(this.model, this.skin);
328 int s = get_model_parameters_species;
329 get_model_parameters(string_null, 0);
330 if (s < 0) return SPECIES_HUMAN;
334 .float model_randomizer;
335 void FixPlayermodel(entity player)
337 string defaultmodel = "";
339 if(autocvar_sv_defaultcharacter)
343 string s = Static_Team_ColorName_Lower(player.team);
346 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
347 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
351 if(defaultmodel == "")
353 defaultmodel = autocvar_sv_defaultplayermodel;
354 defaultskin = autocvar_sv_defaultplayerskin;
357 int n = tokenize_console(defaultmodel);
360 defaultmodel = argv(floor(n * player.model_randomizer));
361 // However, do NOT randomize if the player-selected model is in the list.
362 for (int i = 0; i < n; ++i)
363 if ((argv(i) == player.playermodel && defaultskin == stof(player.playerskin)) || argv(i) == strcat(player.playermodel, ":", player.playerskin))
364 defaultmodel = argv(i);
367 int i = strstrofs(defaultmodel, ":", 0);
370 defaultskin = stof(substring(defaultmodel, i+1, -1));
371 defaultmodel = substring(defaultmodel, 0, i);
374 if(autocvar_sv_defaultcharacterskin && !defaultskin)
378 string s = Static_Team_ColorName_Lower(player.team);
380 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
384 defaultskin = autocvar_sv_defaultplayerskin;
387 MUTATOR_CALLHOOK(FixPlayermodel, defaultmodel, defaultskin);
388 defaultmodel = ret_string;
389 defaultskin = ret_int;
393 if(defaultmodel != "")
395 if (defaultmodel != player.model)
397 vector m1 = player.mins;
398 vector m2 = player.maxs;
399 setplayermodel (player, defaultmodel);
400 setsize (player, m1, m2);
404 oldskin = player.skin;
405 player.skin = defaultskin;
407 if (player.playermodel != player.model || player.playermodel == "")
409 player.playermodel = CheckPlayerModel(player.playermodel); // this is never "", so no endless loop
410 vector m1 = player.mins;
411 vector m2 = player.maxs;
412 setplayermodel (player, player.playermodel);
413 setsize (player, m1, m2);
417 if(!autocvar_sv_defaultcharacterskin)
419 oldskin = player.skin;
420 player.skin = stof(player.playerskin);
424 oldskin = player.skin;
425 player.skin = defaultskin;
429 if(chmdl || oldskin != player.skin) // model or skin has changed
431 player.species = player_getspecies(player); // update species
432 if(!autocvar_g_debug_globalsounds)
433 UpdatePlayerSounds(player); // update skin sounds
437 if(strlen(autocvar_sv_defaultplayercolors))
438 if(player.clientcolors != stof(autocvar_sv_defaultplayercolors))
439 setcolor(player, stof(autocvar_sv_defaultplayercolors));
443 /** Called when a client spawns in the server */
444 void PutClientInServer()
447 if (IS_BOT_CLIENT(this)) {
448 TRANSMUTE(Player, this);
449 } else if (IS_REAL_CLIENT(this)) {
451 WriteByte(MSG_ONE, SVC_SETVIEW);
452 WriteEntity(MSG_ONE, this);
455 TRANSMUTE(Observer, this);
458 SetSpectatee(this, NULL);
463 MUTATOR_CALLHOOK(PutClientInServer, this);
465 if (IS_OBSERVER(this)) {
466 PutObserverInServer();
467 } else if (IS_PLAYER(this)) {
468 PlayerState_attach(this);
469 accuracy_resend(this);
472 JoinBestTeam(this, false, true);
474 entity spot = SelectSpawnPoint(false);
476 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
477 return; // spawn failed
480 TRANSMUTE(Player, this);
481 this.wasplayer = true;
482 this.iscreature = true;
483 this.teleportable = TELEPORT_NORMAL;
484 this.damagedbycontents = true;
485 this.movetype = MOVETYPE_WALK;
486 this.solid = SOLID_SLIDEBOX;
487 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
488 if (autocvar_g_playerclip_collisions)
489 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
490 if (IS_BOT_CLIENT(this) && autocvar_g_botclip_collisions)
491 this.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
492 this.frags = FRAGS_PLAYER;
493 if (INDEPENDENT_PLAYERS) MAKE_INDEPENDENT_PLAYER(this);
494 this.flags = FL_CLIENT | FL_PICKUPITEMS;
495 if (autocvar__notarget)
496 this.flags |= FL_NOTARGET;
497 this.takedamage = DAMAGE_AIM;
498 this.effects = EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
502 this.ammo_shells = warmup_start_ammo_shells;
503 this.ammo_nails = warmup_start_ammo_nails;
504 this.ammo_rockets = warmup_start_ammo_rockets;
505 this.ammo_cells = warmup_start_ammo_cells;
506 this.ammo_plasma = warmup_start_ammo_plasma;
507 this.ammo_fuel = warmup_start_ammo_fuel;
508 this.health = warmup_start_health;
509 this.armorvalue = warmup_start_armorvalue;
510 this.weapons = WARMUP_START_WEAPONS;
512 this.ammo_shells = start_ammo_shells;
513 this.ammo_nails = start_ammo_nails;
514 this.ammo_rockets = start_ammo_rockets;
515 this.ammo_cells = start_ammo_cells;
516 this.ammo_plasma = start_ammo_plasma;
517 this.ammo_fuel = start_ammo_fuel;
518 this.health = start_health;
519 this.armorvalue = start_armorvalue;
520 this.weapons = start_weapons;
523 this.superweapons_finished = (this.weapons & WEPSET_SUPERWEAPONS) ? time + autocvar_g_balance_superweapons_time : 0;
525 this.items = start_items;
527 this.spawnshieldtime = time + autocvar_g_spawnshieldtime;
528 this.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
529 this.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
530 this.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
531 this.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
532 // extend the pause of rotting if client was reset at the beginning of the countdown
533 if (!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
534 float f = game_starttime - time;
535 this.spawnshieldtime += f;
536 this.pauserotarmor_finished += f;
537 this.pauserothealth_finished += f;
538 this.pauseregen_finished += f;
540 this.damageforcescale = 2;
542 this.respawn_flags = 0;
543 this.respawn_time = 0;
544 this.stat_respawn_time = 0;
545 this.scale = autocvar_sv_player_scale;
548 this.pain_finished = 0;
550 this.think = func_null; // players have no think function
553 this.ballistics_density = autocvar_g_ballistics_density_player;
555 this.deadflag = DEAD_NO;
557 this.angles = spot.angles;
558 this.angles_z = 0; // never spawn tilted even if the spot says to
559 if (IS_BOT_CLIENT(this))
560 this.v_angle = this.angles;
561 this.fixangle = true; // turn this way immediately
562 this.oldvelocity = this.velocity = '0 0 0';
563 this.avelocity = '0 0 0';
564 this.punchangle = '0 0 0';
565 this.punchvector = '0 0 0';
567 this.strength_finished = 0;
568 this.invincible_finished = 0;
569 this.fire_endtime = -1;
570 this.revival_time = 0;
571 this.air_finished = time + 12;
573 entity spawnevent = new_pure(spawnevent);
574 spawnevent.owner = this;
575 Net_LinkEntity(spawnevent, false, 0.5, SpawnEvent_Send);
577 // Cut off any still running player sounds.
578 stopsound(this, CH_PLAYER_SINGLE);
581 FixPlayermodel(this);
582 this.drawonlytoclient = NULL;
585 this.view_ofs = STAT(PL_VIEW_OFS, NULL);
586 setsize(this, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
587 this.spawnorigin = spot.origin;
588 setorigin(this, spot.origin + '0 0 1' * (1 - this.mins.z - 24));
589 // don't reset back to last position, even if new position is stuck in solid
590 this.oldorigin = this.origin;
591 this.prevorigin = this.origin;
592 this.lastteleporttime = time; // prevent insane speeds due to changing origin
593 this.conveyor = NULL; // prevent conveyors at the previous location from moving a freshly spawned player
594 this.hud = HUD_NORMAL;
596 this.event_damage = PlayerDamage;
598 this.bot_attack = true;
599 this.monster_attack = true;
601 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_JUMP(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
603 if (this.killcount == FRAGS_SPECTATOR) {
604 PlayerScore_Clear(this);
608 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
610 CL_SpawnWeaponentity(this, weaponentities[slot]);
612 this.alpha = default_player_alpha;
613 this.colormod = '1 1 1' * autocvar_g_player_brightness;
614 this.exteriorweaponentity.alpha = default_weapon_alpha;
616 this.speedrunning = false;
618 target_voicescript_clear(this);
620 // reset fields the weapons may use
621 FOREACH(Weapons, true, LAMBDA(
622 it.wr_resetplayer(it);
623 // reload all reloadable weapons
624 if (it.spawnflags & WEP_FLAG_RELOADABLE) {
625 this.weapon_load[it.m_id] = it.reloading_ammo;
630 string s = spot.target;
631 spot.target = string_null;
632 SUB_UseTargets(spot, this, NULL);
638 MUTATOR_CALLHOOK(PlayerSpawn, spot);
640 if (autocvar_spawn_debug)
642 sprint(this, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
643 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
646 PS(this).m_switchweapon = w_getbestweapon(this);
647 this.cnt = -1; // W_LastWeapon will not complain
648 PS(this).m_weapon = WEP_Null;
649 this.weaponname = "";
650 PS(this).m_switchingweapon = WEP_Null;
652 if (!warmup_stage && !this.alivetime)
653 this.alivetime = time;
655 antilag_clear(this, CS(this));
659 void ClientInit_misc();
661 .float ebouncefactor, ebouncestop; // electro's values
662 // TODO do we need all these fields, or should we stop autodetecting runtime
663 // changes and just have a console command to update this?
664 bool ClientInit_SendEntity(entity this, entity to, int sf)
666 WriteHeader(MSG_ENTITY, _ENT_CLIENT_INIT);
669 // MSG_INIT replacement
670 // TODO: make easier to use
672 W_PROP_reload(MSG_ONE, to);
674 MUTATOR_CALLHOOK(Ent_Init);
676 void ClientInit_misc()
679 int channel = MSG_ONE;
680 WriteHeader(channel, ENT_CLIENT_INIT);
681 WriteByte(channel, g_nexball_meter_period * 32);
682 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[0]));
683 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[1]));
684 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[2]));
685 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[3]));
686 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[0]));
687 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[1]));
688 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[2]));
689 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[3]));
691 if(sv_foginterval && world.fog != "")
692 WriteString(channel, world.fog);
694 WriteString(channel, "");
695 WriteByte(channel, this.count * 255.0); // g_balance_armor_blockpercent
696 WriteByte(channel, serverflags); // client has to know if it should zoom or not
697 WriteCoord(channel, autocvar_g_trueaim_minrange);
700 void ClientInit_CheckUpdate()
702 this.nextthink = time;
703 if(this.count != autocvar_g_balance_armor_blockpercent)
705 this.count = autocvar_g_balance_armor_blockpercent;
710 void ClientInit_Spawn()
713 entity e = new_pure(clientinit);
714 e.think = ClientInit_CheckUpdate;
715 Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
717 WITHSELF(e, ClientInit_CheckUpdate());
727 // initialize parms for a new player
728 parm1 = -(86400 * 366);
730 MUTATOR_CALLHOOK(SetNewParms);
738 void SetChangeParms ()
740 // save parms for level change
741 parm1 = this.parm_idlesince - time;
743 MUTATOR_CALLHOOK(SetChangeParms);
751 void DecodeLevelParms(entity this)
754 this.parm_idlesince = parm1;
755 if (this.parm_idlesince == -(86400 * 366))
756 this.parm_idlesince = time;
758 // whatever happens, allow 60 seconds of idling directly after connect for map loading
759 this.parm_idlesince = max(this.parm_idlesince, time - sv_maxidle + 60);
761 MUTATOR_CALLHOOK(DecodeLevelParms);
768 Called when a client types 'kill' in the console
772 .float clientkill_nexttime;
773 void ClientKill_Now_TeamChange(entity this)
775 if(this.killindicator_teamchange == -1)
777 JoinBestTeam( this, false, true );
779 else if(this.killindicator_teamchange == -2)
782 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
783 WITHSELF(this, PutObserverInServer());
786 WITHSELF(this, SV_ChangeTeam(this.killindicator_teamchange - 1));
787 this.killindicator_teamchange = 0;
790 void ClientKill_Now()
794 vehicles_exit(VHEF_RELEASE);
795 if(!this.killindicator_teamchange)
797 this.vehicle_health = -1;
798 Damage(this, this, this, 1 , DEATH_KILL.m_id, this.origin, '0 0 0');
802 if(this.killindicator && !wasfreed(this.killindicator))
803 remove(this.killindicator);
805 this.killindicator = world;
807 if(this.killindicator_teamchange)
808 ClientKill_Now_TeamChange(this);
811 Damage(this, this, this, 100000, DEATH_KILL.m_id, this.origin, '0 0 0');
813 // now I am sure the player IS dead
815 void KillIndicator_Think()
819 this.owner.killindicator = world;
824 if (this.owner.alpha < 0 && !this.owner.vehicle)
826 this.owner.killindicator = world;
833 WITHSELF(this.owner, ClientKill_Now());
836 else if(g_cts && this.health == 1) // health == 1 means that it's silent
838 this.nextthink = time + 1;
844 setmodel(this, MDL_NUM(this.cnt));
845 if(IS_REAL_CLIENT(this.owner))
848 { Send_Notification(NOTIF_ONE, this.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, this.cnt)); }
850 this.nextthink = time + 1;
855 float clientkilltime;
856 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
865 killtime = autocvar_g_balance_kill_delay;
867 if(g_race_qualifying || g_cts)
870 if(MUTATOR_CALLHOOK(ClientKill, this, killtime))
873 this.killindicator_teamchange = targetteam;
875 if(!this.killindicator)
879 killtime = max(killtime, this.clientkill_nexttime - time);
880 this.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
883 if(killtime <= 0 || !IS_PLAYER(this) || IS_DEAD(this))
889 starttime = max(time, clientkilltime);
891 this.killindicator = spawn();
892 this.killindicator.owner = this;
893 this.killindicator.scale = 0.5;
894 setattachment(this.killindicator, this, "");
895 setorigin(this.killindicator, '0 0 52');
896 this.killindicator.think = KillIndicator_Think;
897 this.killindicator.nextthink = starttime + (this.lip) * 0.05;
898 clientkilltime = max(clientkilltime, this.killindicator.nextthink + 0.05);
899 this.killindicator.cnt = ceil(killtime);
900 this.killindicator.count = bound(0, ceil(killtime), 10);
901 //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
903 for(e = world; (e = find(e, classname, "body")) != world; )
907 e.killindicator = spawn();
908 e.killindicator.owner = e;
909 e.killindicator.scale = 0.5;
910 setattachment(e.killindicator, e, "");
911 setorigin(e.killindicator, '0 0 52');
912 e.killindicator.think = KillIndicator_Think;
913 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
914 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
915 e.killindicator.cnt = ceil(killtime);
920 if(this.killindicator)
922 if(targetteam == 0) // just die
924 this.killindicator.colormod = '0 0 0';
925 if(IS_REAL_CLIENT(this))
926 if(this.killindicator.cnt > 0)
927 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, this.killindicator.cnt);
929 else if(targetteam == -1) // auto
931 this.killindicator.colormod = '0 1 0';
932 if(IS_REAL_CLIENT(this))
933 if(this.killindicator.cnt > 0)
934 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, this.killindicator.cnt);
936 else if(targetteam == -2) // spectate
938 this.killindicator.colormod = '0.5 0.5 0.5';
939 if(IS_REAL_CLIENT(this))
940 if(this.killindicator.cnt > 0)
941 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, this.killindicator.cnt);
945 this.killindicator.colormod = Team_ColorRGB(targetteam);
946 if(IS_REAL_CLIENT(this))
947 if(this.killindicator.cnt > 0)
948 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE), this.killindicator.cnt);
957 if(this.player_blocked) return;
958 if(STAT(FROZEN, this)) return;
960 ClientKill_TeamChange(0);
963 void FixClientCvars(entity e)
965 // send prediction settings to the client
966 stuffcmd(e, "\nin_bindmap 0 0\n");
967 if(autocvar_g_antilag == 3) // client side hitscan
968 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
969 if(autocvar_sv_gentle)
970 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
972 MUTATOR_CALLHOOK(FixClientCvars, e);
975 float PlayerInIDList(entity p, string idlist)
980 // NOTE: we do NOT check crypto_idfp_signed here, an unsigned ID is fine too for this
984 // this function allows abbreviated player IDs too!
985 n = tokenize_console(idlist);
986 for(i = 0; i < n; ++i)
989 if(s == substring(p.crypto_idfp, 0, strlen(s)))
996 #ifdef DP_EXT_PRECONNECT
1001 Called once (not at each match start) when a client begins a connection to the server
1004 void ClientPreConnect ()
1006 if(autocvar_sv_eventlog)
1008 GameLogEcho(sprintf(":connect:%d:%d:%s",
1011 ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot")
1021 Called when a client connects to the server
1024 void ClientConnect()
1027 if (Ban_MaybeEnforceBanOnce(this)) return;
1028 assert(!IS_CLIENT(this), return);
1029 this.flags |= FL_CLIENT;
1030 assert(player_count >= 0, player_count = 0);
1033 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_WATERMARK, WATERMARK);
1035 this.version_nagtime = time + 10 + random() * 10;
1036 TRANSMUTE(Client, this);
1038 // identify the right forced team
1039 if (autocvar_g_campaign)
1041 if (IS_REAL_CLIENT(this)) // only players, not bots
1043 switch (autocvar_g_campaign_forceteam)
1045 case 1: this.team_forced = NUM_TEAM_1; break;
1046 case 2: this.team_forced = NUM_TEAM_2; break;
1047 case 3: this.team_forced = NUM_TEAM_3; break;
1048 case 4: this.team_forced = NUM_TEAM_4; break;
1049 default: this.team_forced = 0;
1053 else if (PlayerInIDList(this, autocvar_g_forced_team_red)) this.team_forced = NUM_TEAM_1;
1054 else if (PlayerInIDList(this, autocvar_g_forced_team_blue)) this.team_forced = NUM_TEAM_2;
1055 else if (PlayerInIDList(this, autocvar_g_forced_team_yellow)) this.team_forced = NUM_TEAM_3;
1056 else if (PlayerInIDList(this, autocvar_g_forced_team_pink)) this.team_forced = NUM_TEAM_4;
1057 else switch (autocvar_g_forced_team_otherwise)
1059 default: this.team_forced = 0; break;
1060 case "red": this.team_forced = NUM_TEAM_1; break;
1061 case "blue": this.team_forced = NUM_TEAM_2; break;
1062 case "yellow": this.team_forced = NUM_TEAM_3; break;
1063 case "pink": this.team_forced = NUM_TEAM_4; break;
1066 this.team_forced = -1;
1069 if (!teamplay && this.team_forced > 0) this.team_forced = 0;
1072 int id = this.playerid;
1073 this.playerid = 0; // silent
1074 JoinBestTeam(this, false, false); // if the team number is valid, keep it
1078 if (autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) {
1079 TRANSMUTE(Observer, this);
1081 if (!teamplay || autocvar_g_balance_teams) {
1082 TRANSMUTE(Player, this);
1083 campaign_bots_may_start = true;
1085 TRANSMUTE(Observer, this); // do it anyway
1089 PlayerStats_GameReport_AddEvent(sprintf("kills-%d", this.playerid));
1091 // always track bots, don't ask for cl_allow_uidtracking
1092 if (IS_BOT_CLIENT(this)) PlayerStats_GameReport_AddPlayer(this);
1094 if (autocvar_sv_eventlog)
1095 GameLogEcho(strcat(":join:", ftos(this.playerid), ":", ftos(etof(this)), ":", ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot"), ":", this.netname));
1097 LogTeamchange(this.playerid, this.team, 1);
1099 this.just_joined = true; // stop spamming the eventlog with additional lines when the client connects
1101 this.netname_previous = strzone(this.netname);
1103 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && IS_PLAYER(this)) ? APP_TEAM_ENT(this, INFO_JOIN_CONNECT_TEAM) : INFO_JOIN_CONNECT), this.netname);
1105 stuffcmd(this, clientstuff, "\n");
1106 stuffcmd(this, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1108 FixClientCvars(this);
1110 // get version info from player
1111 stuffcmd(this, "cmd clientversion $gameversion\n");
1113 // notify about available teams
1116 CheckAllowedTeams(this);
1118 if (c1 >= 0) t |= BIT(0);
1119 if (c2 >= 0) t |= BIT(1);
1120 if (c3 >= 0) t |= BIT(2);
1121 if (c4 >= 0) t |= BIT(3);
1122 stuffcmd(this, sprintf("set _teams_available %d\n", t));
1126 stuffcmd(this, "set _teams_available 0\n");
1129 bot_relinkplayerlist();
1131 this.spectatortime = time;
1132 if (blockSpectators)
1134 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1137 this.jointime = time;
1138 this.allowed_timeouts = autocvar_sv_timeout_number;
1140 if (IS_REAL_CLIENT(this))
1142 if (!autocvar_g_campaign)
1144 this.motd_actived_time = -1;
1145 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1148 if (g_weaponarena_weapons == WEPSET(TUBA))
1149 stuffcmd(this, "cl_cmd settemp chase_active 1\n");
1152 if (!sv_foginterval && world.fog != "")
1153 stuffcmd(this, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1155 if (autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)))
1156 if (!g_ca && !g_cts && !g_race) // teamnagger is currently bad for ca, race & cts
1157 send_CSQC_teamnagger();
1159 CSQCMODEL_AUTOINIT(this);
1161 this.model_randomizer = random();
1163 if (IS_REAL_CLIENT(this))
1164 sv_notice_join(this);
1166 FOREACH_ENTITY_FLOAT(init_for_player_needed, true, {
1167 WITHSELF(it, it.init_for_player(it));
1170 MUTATOR_CALLHOOK(ClientConnect, this);
1176 Called when a client disconnects from the server
1179 .entity chatbubbleentity;
1181 void ClientDisconnect()
1184 assert(IS_CLIENT(this), return);
1186 PlayerStats_GameReport_FinalizePlayer(this);
1187 if (this.vehicle) vehicles_exit(VHEF_RELEASE);
1188 if (this.active_minigame) part_minigame(this);
1189 if (IS_PLAYER(this)) Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
1191 if (autocvar_sv_eventlog)
1192 GameLogEcho(strcat(":part:", ftos(this.playerid)));
1194 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
1196 MUTATOR_CALLHOOK(ClientDisconnect);
1198 ClientState_detach(this);
1200 Portal_ClearAll(this);
1204 RemoveGrapplingHook(this);
1206 // Here, everything has been done that requires this player to be a client.
1208 this.flags &= ~FL_CLIENT;
1210 if (this.chatbubbleentity) remove(this.chatbubbleentity);
1211 if (this.killindicator) remove(this.killindicator);
1213 WaypointSprite_PlayerGone();
1215 bot_relinkplayerlist();
1217 if (this.netname_previous) strunzone(this.netname_previous);
1218 if (this.clientstatus) strunzone(this.clientstatus);
1219 if (this.weaponorder_byimpulse) strunzone(this.weaponorder_byimpulse);
1220 if (this.personal) remove(this.personal);
1224 if (vote_called && IS_REAL_CLIENT(this)) VoteCount(false);
1227 void ChatBubbleThink()
1229 this.nextthink = time;
1230 if ((this.owner.alpha < 0) || this.owner.chatbubbleentity != this)
1232 if(this.owner) // but why can that ever be world?
1233 this.owner.chatbubbleentity = world;
1240 if ( !IS_DEAD(this.owner) && IS_PLAYER(this.owner) )
1242 if ( this.owner.active_minigame )
1243 this.mdl = "models/sprites/minigame_busy.iqm";
1244 else if (PHYS_INPUT_BUTTON_CHAT(this.owner))
1245 this.mdl = "models/misc/chatbubble.spr";
1248 if ( this.model != this.mdl )
1249 _setmodel(this, this.mdl);
1253 void UpdateChatBubble()
1257 // spawn a chatbubble entity if needed
1258 if (!this.chatbubbleentity)
1260 this.chatbubbleentity = new(chatbubbleentity);
1261 this.chatbubbleentity.owner = this;
1262 this.chatbubbleentity.exteriormodeltoclient = this;
1263 this.chatbubbleentity.think = ChatBubbleThink;
1264 this.chatbubbleentity.nextthink = time;
1265 setmodel(this.chatbubbleentity, MDL_CHAT); // precision set below
1266 //setorigin(this.chatbubbleentity, this.origin + '0 0 15' + this.maxs_z * '0 0 1');
1267 setorigin(this.chatbubbleentity, '0 0 15' + this.maxs_z * '0 0 1');
1268 setattachment(this.chatbubbleentity, this, ""); // sticks to moving player better, also conserves bandwidth
1269 this.chatbubbleentity.mdl = this.chatbubbleentity.model;
1270 //this.chatbubbleentity.model = "";
1271 this.chatbubbleentity.effects = EF_LOWPRECISION;
1276 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1277 // added to the model skins
1278 /*void UpdateColorModHack()
1281 c = this.clientcolors & 15;
1282 // LordHavoc: only bothering to support white, green, red, yellow, blue
1283 if (!teamplay) this.colormod = '0 0 0';
1284 else if (c == 0) this.colormod = '1.00 1.00 1.00';
1285 else if (c == 3) this.colormod = '0.10 1.73 0.10';
1286 else if (c == 4) this.colormod = '1.73 0.10 0.10';
1287 else if (c == 12) this.colormod = '1.22 1.22 0.10';
1288 else if (c == 13) this.colormod = '0.10 0.10 1.73';
1289 else this.colormod = '1 1 1';
1294 if(this.alpha >= 0 && autocvar_g_respawn_ghosts)
1296 this.solid = SOLID_NOT;
1297 this.takedamage = DAMAGE_NO;
1298 this.movetype = MOVETYPE_FLY;
1299 this.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1300 this.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1301 this.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1302 Send_Effect(EFFECT_RESPAWN_GHOST, this.origin, '0 0 0', 1);
1303 if(autocvar_g_respawn_ghosts_maxtime)
1304 SUB_SetFade (this, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1309 this.effects |= EF_NODRAW; // prevent another CopyBody
1310 PutClientInServer();
1313 void play_countdown(float finished, Sound samp)
1316 if(IS_REAL_CLIENT(this))
1317 if(floor(finished - time - frametime) != floor(finished - time))
1318 if(finished - time < 6)
1319 sound (this, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
1322 void player_powerups ()
1324 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1325 int items_prev = this.items;
1327 if((this.items & IT_USING_JETPACK) && !IS_DEAD(this) && !gameover)
1328 this.modelflags |= MF_ROCKET;
1330 this.modelflags &= ~MF_ROCKET;
1332 this.effects &= ~(EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1334 if((this.alpha < 0 || IS_DEAD(this)) && !this.vehicle) // don't apply the flags if the player is gibbed
1337 Fire_ApplyDamage(this);
1338 Fire_ApplyEffect(this);
1342 if (this.items & ITEM_Strength.m_itemid)
1344 play_countdown(this.strength_finished, SND_POWEROFF);
1345 this.effects = this.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1346 if (time > this.strength_finished)
1348 this.items = this.items - (this.items & ITEM_Strength.m_itemid);
1349 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, this.netname);
1350 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
1355 if (time < this.strength_finished)
1357 this.items = this.items | ITEM_Strength.m_itemid;
1358 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, this.netname);
1359 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERUP_STRENGTH);
1362 if (this.items & ITEM_Shield.m_itemid)
1364 play_countdown(this.invincible_finished, SND_POWEROFF);
1365 this.effects = this.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1366 if (time > this.invincible_finished)
1368 this.items = this.items - (this.items & ITEM_Shield.m_itemid);
1369 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, this.netname);
1370 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
1375 if (time < this.invincible_finished)
1377 this.items = this.items | ITEM_Shield.m_itemid;
1378 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, this.netname);
1379 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERUP_SHIELD);
1382 if (this.items & IT_SUPERWEAPON)
1384 if (!(this.weapons & WEPSET_SUPERWEAPONS))
1386 this.superweapons_finished = 0;
1387 this.items = this.items - (this.items & IT_SUPERWEAPON);
1388 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, this.netname);
1389 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1391 else if (this.items & IT_UNLIMITED_SUPERWEAPONS)
1393 // don't let them run out
1397 play_countdown(this.superweapons_finished, SND_POWEROFF);
1398 if (time > this.superweapons_finished)
1400 this.items = this.items - (this.items & IT_SUPERWEAPON);
1401 this.weapons &= ~WEPSET_SUPERWEAPONS;
1402 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, this.netname);
1403 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1407 else if(this.weapons & WEPSET_SUPERWEAPONS)
1409 if (time < this.superweapons_finished || (this.items & IT_UNLIMITED_SUPERWEAPONS))
1411 this.items = this.items | IT_SUPERWEAPON;
1412 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, this.netname);
1413 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1417 this.superweapons_finished = 0;
1418 this.weapons &= ~WEPSET_SUPERWEAPONS;
1423 this.superweapons_finished = 0;
1427 if(autocvar_g_nodepthtestplayers)
1428 this.effects = this.effects | EF_NODEPTHTEST;
1430 if(autocvar_g_fullbrightplayers)
1431 this.effects = this.effects | EF_FULLBRIGHT;
1433 if (time >= game_starttime)
1434 if (time < this.spawnshieldtime)
1435 this.effects = this.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1437 MUTATOR_CALLHOOK(PlayerPowerups, this, items_prev);
1440 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1442 if(current > stable)
1444 else if(current > stable - 0.25) // when close enough, "snap"
1447 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1450 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1452 if(current < stable)
1454 else if(current < stable + 0.25) // when close enough, "snap"
1457 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1460 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1462 if(current > rotstable)
1464 if(rotframetime > 0)
1466 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1467 current = max(rotstable, current - rotlinear * rotframetime);
1470 else if(current < regenstable)
1472 if(regenframetime > 0)
1474 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1475 current = min(regenstable, current + regenlinear * regenframetime);
1485 void player_regen ()
1487 float max_mod, regen_mod, rot_mod, limit_mod;
1488 max_mod = regen_mod = rot_mod = limit_mod = 1;
1489 regen_mod_max = max_mod;
1490 regen_mod_regen = regen_mod;
1491 regen_mod_rot = rot_mod;
1492 regen_mod_limit = limit_mod;
1494 regen_health = autocvar_g_balance_health_regen;
1495 regen_health_linear = autocvar_g_balance_health_regenlinear;
1496 regen_health_rot = autocvar_g_balance_health_rot;
1497 regen_health_rotlinear = autocvar_g_balance_health_rotlinear;
1498 regen_health_stable = autocvar_g_balance_health_regenstable;
1499 regen_health_rotstable = autocvar_g_balance_health_rotstable;
1500 if(!MUTATOR_CALLHOOK(PlayerRegen))
1501 if(!STAT(FROZEN, this))
1503 float mina, maxa, limith, limita;
1504 maxa = autocvar_g_balance_armor_rotstable;
1505 mina = autocvar_g_balance_armor_regenstable;
1506 limith = autocvar_g_balance_health_limit;
1507 limita = autocvar_g_balance_armor_limit;
1509 max_mod = regen_mod_max;
1510 regen_mod = regen_mod_regen;
1511 rot_mod = regen_mod_rot;
1512 limit_mod = regen_mod_limit;
1514 regen_health_rotstable = regen_health_rotstable * max_mod;
1515 regen_health_stable = regen_health_stable * max_mod;
1516 limith = limith * limit_mod;
1517 limita = limita * limit_mod;
1519 this.armorvalue = CalcRotRegen(this.armorvalue, mina, autocvar_g_balance_armor_regen, autocvar_g_balance_armor_regenlinear, regen_mod * frametime * (time > this.pauseregen_finished), maxa, autocvar_g_balance_armor_rot, autocvar_g_balance_armor_rotlinear, rot_mod * frametime * (time > this.pauserotarmor_finished), limita);
1520 this.health = CalcRotRegen(this.health, regen_health_stable, regen_health, regen_health_linear, regen_mod * frametime * (time > this.pauseregen_finished), regen_health_rotstable, regen_health_rot, regen_health_rotlinear, rot_mod * frametime * (time > this.pauserothealth_finished), limith);
1523 // if player rotted to death... die!
1524 // check this outside above checks, as player may still be able to rot to death
1528 vehicles_exit(VHEF_RELEASE);
1529 if(this.event_damage)
1530 this.event_damage(this, this, this, 1, DEATH_ROT.m_id, this.origin, '0 0 0');
1533 if (!(this.items & IT_UNLIMITED_WEAPON_AMMO))
1535 float minf, maxf, limitf;
1537 maxf = autocvar_g_balance_fuel_rotstable;
1538 minf = autocvar_g_balance_fuel_regenstable;
1539 limitf = autocvar_g_balance_fuel_limit;
1541 this.ammo_fuel = CalcRotRegen(this.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, frametime * (time > this.pauseregen_finished) * ((this.items & ITEM_JetpackRegen.m_itemid) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > this.pauserotfuel_finished), limitf);
1546 void SetZoomState(float z)
1548 if(z != this.zoomstate)
1551 ClientData_Touch(this);
1553 zoomstate_set = true;
1556 void GetPressedKeys()
1559 MUTATOR_CALLHOOK(GetPressedKeys);
1560 int keys = this.pressedkeys;
1561 keys = BITSET(keys, KEY_FORWARD, this.movement.x > 0);
1562 keys = BITSET(keys, KEY_BACKWARD, this.movement.x < 0);
1563 keys = BITSET(keys, KEY_RIGHT, this.movement.y > 0);
1564 keys = BITSET(keys, KEY_LEFT, this.movement.y < 0);
1566 keys = BITSET(keys, KEY_JUMP, PHYS_INPUT_BUTTON_JUMP(this));
1567 keys = BITSET(keys, KEY_CROUCH, PHYS_INPUT_BUTTON_CROUCH(this));
1568 keys = BITSET(keys, KEY_ATCK, PHYS_INPUT_BUTTON_ATCK(this));
1569 keys = BITSET(keys, KEY_ATCK2, PHYS_INPUT_BUTTON_ATCK2(this));
1570 this.pressedkeys = keys;
1574 ======================
1575 spectate mode routines
1576 ======================
1579 void SpectateCopy(entity this, entity spectatee)
1581 TC(Client, this); TC(Client, spectatee);
1583 MUTATOR_CALLHOOK(SpectateCopy, spectatee, this);
1584 PS(this) = PS(spectatee);
1585 this.armortype = spectatee.armortype;
1586 this.armorvalue = spectatee.armorvalue;
1587 this.ammo_cells = spectatee.ammo_cells;
1588 this.ammo_plasma = spectatee.ammo_plasma;
1589 this.ammo_shells = spectatee.ammo_shells;
1590 this.ammo_nails = spectatee.ammo_nails;
1591 this.ammo_rockets = spectatee.ammo_rockets;
1592 this.ammo_fuel = spectatee.ammo_fuel;
1593 this.clip_load = spectatee.clip_load;
1594 this.clip_size = spectatee.clip_size;
1595 this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1596 this.health = spectatee.health;
1598 this.items = spectatee.items;
1599 this.last_pickup = spectatee.last_pickup;
1600 this.hit_time = spectatee.hit_time;
1601 this.strength_finished = spectatee.strength_finished;
1602 this.invincible_finished = spectatee.invincible_finished;
1603 this.pressedkeys = spectatee.pressedkeys;
1604 this.weapons = spectatee.weapons;
1605 this.vortex_charge = spectatee.vortex_charge;
1606 this.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
1607 this.hagar_load = spectatee.hagar_load;
1608 this.arc_heat_percent = spectatee.arc_heat_percent;
1609 this.minelayer_mines = spectatee.minelayer_mines;
1610 this.punchangle = spectatee.punchangle;
1611 this.view_ofs = spectatee.view_ofs;
1612 this.velocity = spectatee.velocity;
1613 this.dmg_take = spectatee.dmg_take;
1614 this.dmg_save = spectatee.dmg_save;
1615 this.dmg_inflictor = spectatee.dmg_inflictor;
1616 this.v_angle = spectatee.v_angle;
1617 this.angles = spectatee.v_angle;
1618 STAT(FROZEN, this) = STAT(FROZEN, spectatee);
1619 this.revive_progress = spectatee.revive_progress;
1620 if(!PHYS_INPUT_BUTTON_USE(this))
1621 this.fixangle = true;
1622 setorigin(this, spectatee.origin);
1623 setsize(this, spectatee.mins, spectatee.maxs);
1624 SetZoomState(spectatee.zoomstate);
1626 anticheat_spectatecopy(this, spectatee);
1627 this.hud = spectatee.hud;
1628 if(spectatee.vehicle)
1630 this.fixangle = false;
1631 //this.velocity = spectatee.vehicle.velocity;
1632 this.vehicle_health = spectatee.vehicle_health;
1633 this.vehicle_shield = spectatee.vehicle_shield;
1634 this.vehicle_energy = spectatee.vehicle_energy;
1635 this.vehicle_ammo1 = spectatee.vehicle_ammo1;
1636 this.vehicle_ammo2 = spectatee.vehicle_ammo2;
1637 this.vehicle_reload1 = spectatee.vehicle_reload1;
1638 this.vehicle_reload2 = spectatee.vehicle_reload2;
1642 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1643 WriteAngle(MSG_ONE, spectatee.v_angle.x);
1644 WriteAngle(MSG_ONE, spectatee.v_angle.y);
1645 WriteAngle(MSG_ONE, spectatee.v_angle.z);
1647 //WriteByte (MSG_ONE, SVC_SETVIEW);
1648 // WriteEntity(MSG_ONE, this);
1649 //makevectors(spectatee.v_angle);
1650 //setorigin(this, spectatee.origin - v_forward * 400 + v_up * 300);*/
1654 bool SpectateUpdate()
1659 if(!IS_PLAYER(this.enemy) || this == this.enemy)
1661 SetSpectatee(this, NULL);
1665 SpectateCopy(this, this.enemy);
1672 if(!IS_PLAYER(this.enemy))
1676 WriteByte(MSG_ONE, SVC_SETVIEW);
1677 WriteEntity(MSG_ONE, this.enemy);
1678 this.movetype = MOVETYPE_NONE;
1679 accuracy_resend(this);
1681 if(!SpectateUpdate())
1682 PutObserverInServer();
1687 void SetSpectatee(entity player, entity spectatee)
1689 entity old_spectatee = player.enemy;
1691 player.enemy = spectatee;
1694 // these are required to fix the spectator bug with arc
1695 if(old_spectatee && old_spectatee.arc_beam) { old_spectatee.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1696 if(player.enemy && player.enemy.arc_beam) { player.enemy.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1699 bool Spectate(entity pl)
1701 if(MUTATOR_CALLHOOK(SpectateSet, this, pl))
1705 SetSpectatee(this, pl);
1706 return SpectateSet();
1711 other = find(this.enemy, classname, STR_PLAYER);
1713 if (MUTATOR_CALLHOOK(SpectateNext, this, other))
1714 other = spec_player;
1716 other = find(other, classname, STR_PLAYER);
1718 if(other) { SetSpectatee(this, other); }
1720 return SpectateSet();
1725 // NOTE: chain order is from the highest to the lower entnum (unlike find)
1726 other = findchain(classname, STR_PLAYER);
1727 if (!other) // no player
1730 entity first = other;
1731 // skip players until current spectated player
1733 while(other && other != this.enemy)
1734 other = other.chain;
1736 switch (MUTATOR_CALLHOOK(SpectatePrev, this, other, first))
1738 case MUT_SPECPREV_FOUND:
1739 other = spec_player;
1741 case MUT_SPECPREV_RETURN:
1742 other = spec_player;
1744 case MUT_SPECPREV_CONTINUE:
1748 other = other.chain;
1755 SetSpectatee(this, other);
1756 return SpectateSet();
1761 ShowRespawnCountdown()
1763 Update a respawn countdown display.
1766 void ShowRespawnCountdown()
1769 if(!IS_DEAD(this)) // just respawned?
1773 number = ceil(this.respawn_time - time);
1776 if(number <= this.respawn_countdown)
1778 this.respawn_countdown = number - 1;
1779 if(ceil(this.respawn_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
1780 { Send_Notification(NOTIF_ONE, this, MSG_ANNCE, Announcer_PickNumber(CNT_RESPAWN, number)); }
1785 void LeaveSpectatorMode()
1789 if(nJoinAllowed(this, this))
1791 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0)
1793 TRANSMUTE(Player, this);
1795 if(autocvar_g_campaign || autocvar_g_balance_teams)
1796 { JoinBestTeam(this, false, true); }
1798 if(autocvar_g_campaign)
1799 { campaign_bots_may_start = true; }
1801 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_PREVENT_JOIN);
1803 PutClientInServer();
1805 if(IS_PLAYER(this)) { Send_Notification(NOTIF_ALL, world, MSG_INFO, ((teamplay && this.team != -1) ? APP_TEAM_ENT(this, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), this.netname); }
1808 stuffcmd(this, "menu_showteamselect\n");
1812 // Player may not join because g_maxplayers is set
1813 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_PREVENT);
1818 * Determines whether the player is allowed to join. This depends on cvar
1819 * g_maxplayers, if it isn't used this function always return true, otherwise
1820 * it checks whether the number of currently playing players exceeds g_maxplayers.
1821 * @return int number of free slots for players, 0 if none
1823 bool nJoinAllowed(entity this, entity ignore)
1826 // this is called that way when checking if anyone may be able to join (to build qcstatus)
1827 // so report 0 free slots if restricted
1829 if(autocvar_g_forced_team_otherwise == "spectate")
1831 if(autocvar_g_forced_team_otherwise == "spectator")
1835 if(this.team_forced < 0)
1836 return false; // forced spectators can never join
1838 // TODO simplify this
1839 int totalClients = 0;
1840 int currentlyPlaying = 0;
1841 FOREACH_CLIENT(true, LAMBDA(
1844 if(IS_REAL_CLIENT(it))
1845 if(IS_PLAYER(it) || it.caplayer)
1849 if (!autocvar_g_maxplayers)
1850 return maxclients - totalClients;
1852 if(currentlyPlaying < autocvar_g_maxplayers)
1853 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
1859 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1860 * g_maxplayers_spectator_blocktime seconds
1862 void checkSpectatorBlock()
1864 if(IS_SPEC(this) || IS_OBSERVER(this))
1866 if(IS_REAL_CLIENT(this))
1868 if( time > (this.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
1869 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
1875 void PrintWelcomeMessage(entity this)
1877 if(this.motd_actived_time == 0)
1879 if (autocvar_g_campaign) {
1880 if ((IS_PLAYER(this) && PHYS_INPUT_BUTTON_INFO(this)) || (!IS_PLAYER(this))) {
1881 this.motd_actived_time = time;
1882 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, campaign_message);
1885 if (PHYS_INPUT_BUTTON_INFO(this)) {
1886 this.motd_actived_time = time;
1887 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1891 else if(this.motd_actived_time > 0) // showing MOTD or campaign message
1893 if (autocvar_g_campaign) {
1894 if (PHYS_INPUT_BUTTON_INFO(this))
1895 this.motd_actived_time = time;
1896 else if ((time - this.motd_actived_time > 2) && IS_PLAYER(this)) { // hide it some seconds after BUTTON_INFO has been released
1897 this.motd_actived_time = 0;
1898 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1901 if (PHYS_INPUT_BUTTON_INFO(this))
1902 this.motd_actived_time = time;
1903 else if (time - this.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
1904 this.motd_actived_time = 0;
1905 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1909 else //if(this.motd_actived_time < 0) // just connected, motd is active
1911 if(PHYS_INPUT_BUTTON_INFO(this)) // BUTTON_INFO hides initial MOTD
1912 this.motd_actived_time = -2; // wait until BUTTON_INFO gets released
1913 else if(this.motd_actived_time == -2 || IS_PLAYER(this) || IS_SPEC(this))
1915 // instanctly hide MOTD
1916 this.motd_actived_time = 0;
1917 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1922 void ObserverThink()
1926 MinigameImpulse(this, this.impulse);
1929 float prefered_movetype;
1930 if (this.flags & FL_JUMPRELEASED) {
1931 if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) {
1932 this.flags &= ~FL_JUMPRELEASED;
1933 this.flags |= FL_SPAWNING;
1934 } else if(PHYS_INPUT_BUTTON_ATCK(this) && !this.version_mismatch) {
1935 this.flags &= ~FL_JUMPRELEASED;
1936 if(SpectateNext()) {
1937 TRANSMUTE(Spectator, this);
1940 prefered_movetype = ((!PHYS_INPUT_BUTTON_USE(this) ? this.cvar_cl_clippedspectating : !this.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
1941 if (this.movetype != prefered_movetype)
1942 this.movetype = prefered_movetype;
1945 if (!(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_JUMP(this))) {
1946 this.flags |= FL_JUMPRELEASED;
1947 if(this.flags & FL_SPAWNING)
1949 this.flags &= ~FL_SPAWNING;
1950 LeaveSpectatorMode();
1957 void SpectatorThink()
1961 if(MinigameImpulse(this, this.impulse))
1964 if (this.flags & FL_JUMPRELEASED) {
1965 if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) {
1966 this.flags &= ~FL_JUMPRELEASED;
1967 this.flags |= FL_SPAWNING;
1968 } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) {
1969 this.flags &= ~FL_JUMPRELEASED;
1970 if(SpectateNext()) {
1971 TRANSMUTE(Spectator, this);
1973 TRANSMUTE(Observer, this);
1974 PutClientInServer();
1977 } else if(this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229)) {
1978 this.flags &= ~FL_JUMPRELEASED;
1979 if(SpectatePrev()) {
1980 TRANSMUTE(Spectator, this);
1982 TRANSMUTE(Observer, this);
1983 PutClientInServer();
1986 } else if (PHYS_INPUT_BUTTON_ATCK2(this)) {
1987 this.flags &= ~FL_JUMPRELEASED;
1988 TRANSMUTE(Observer, this);
1989 PutClientInServer();
1991 if(!SpectateUpdate())
1992 PutObserverInServer();
1995 if (!(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this))) {
1996 this.flags |= FL_JUMPRELEASED;
1997 if(this.flags & FL_SPAWNING)
1999 this.flags &= ~FL_SPAWNING;
2000 LeaveSpectatorMode();
2004 if(!SpectateUpdate())
2005 PutObserverInServer();
2008 this.flags |= FL_CLIENT | FL_NOTARGET;
2011 void vehicles_enter (entity pl, entity veh);
2014 if (!IS_PLAYER(this))
2021 vehicles_exit(VHEF_NORMAL);
2025 else if(autocvar_g_vehicles_enter)
2027 if(!STAT(FROZEN, this))
2031 entity head, closest_target = world;
2032 head = WarpZone_FindRadius(this.origin, autocvar_g_vehicles_enter_radius, true);
2034 while(head) // find the closest acceptable target to enter
2036 if(head.vehicle_flags & VHF_ISVEHICLE)
2038 if(!head.owner || ((head.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(head.owner, this)))
2039 if(head.takedamage != DAMAGE_NO)
2043 if(vlen(this.origin - head.origin) < vlen(this.origin - closest_target.origin))
2044 { closest_target = head; }
2046 else { closest_target = head; }
2052 if(closest_target) { vehicles_enter(this, closest_target); return; }
2056 // a use key was pressed; call handlers
2057 MUTATOR_CALLHOOK(PlayerUseKey);
2065 Called every frame for each client before the physics are run
2068 .float usekeypressed;
2069 void() nexball_setstatus;
2070 .float last_vehiclecheck;
2072 void PlayerPreThink ()
2075 WarpZone_PlayerPhysics_FixVAngle(this);
2077 STAT(GAMESTARTTIME, this) = game_starttime;
2078 STAT(ROUNDSTARTTIME, this) = round_starttime;
2079 STAT(ALLOW_OLDVORTEXBEAM, this) = autocvar_g_allow_oldvortexbeam;
2080 STAT(LEADLIMIT, this) = autocvar_leadlimit;
2082 STAT(WEAPONSINMAP, this) = weaponsInMap;
2085 // physics frames: update anticheat stuff
2086 anticheat_prethink(this);
2089 if (blockSpectators && frametime) {
2090 // WORKAROUND: only use dropclient in server frames (frametime set).
2091 // Never use it in cl_movement frames (frametime zero).
2092 checkSpectatorBlock();
2095 zoomstate_set = false;
2097 // Check for nameless players
2098 if (isInvisibleString(this.netname)) {
2099 this.netname = strzone(sprintf("Player#%d", this.playerid));
2100 // stuffcmd(this, strcat("name ", this.netname, "\n")); // maybe?
2102 if (this.netname != this.netname_previous) {
2103 if (autocvar_sv_eventlog) {
2104 GameLogEcho(strcat(":name:", ftos(this.playerid), ":", this.netname));
2106 if (this.netname_previous) strunzone(this.netname_previous);
2107 this.netname_previous = strzone(this.netname);
2111 if (this.version_nagtime && this.cvar_g_xonoticversion && time > this.version_nagtime) {
2112 this.version_nagtime = 0;
2113 if (strstrofs(this.cvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(this.cvar_g_xonoticversion, "autobuild", 0) >= 0) {
2115 } else if (strstrofs(autocvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(autocvar_g_xonoticversion, "autobuild", 0) >= 0) {
2117 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2119 int r = vercmp(this.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2120 if (r < 0) { // old client
2121 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2122 } else if (r > 0) { // old server
2123 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2129 if (!(this.flags & FL_GODMODE) && this.max_armorvalue)
2131 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_GODMODE_OFF, this.max_armorvalue);
2132 this.max_armorvalue = 0;
2135 if (STAT(FROZEN, this) == 2)
2137 this.revive_progress = bound(0, this.revive_progress + frametime * this.revive_speed, 1);
2138 this.health = max(1, this.revive_progress * start_health);
2139 this.iceblock.alpha = bound(0.2, 1 - this.revive_progress, 1);
2141 if (this.revive_progress >= 1)
2144 else if (STAT(FROZEN, this) == 3)
2146 this.revive_progress = bound(0, this.revive_progress - frametime * this.revive_speed, 1);
2147 this.health = max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * this.revive_progress );
2149 if (this.health < 1)
2152 vehicles_exit(VHEF_RELEASE);
2153 this.event_damage(this, this, this.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, this.origin, '0 0 0');
2155 else if (this.revive_progress <= 0)
2159 MUTATOR_CALLHOOK(PlayerPreThink);
2161 if(autocvar_g_vehicles_enter)
2162 if(time > this.last_vehiclecheck)
2165 if(!STAT(FROZEN, this))
2170 for(veh = world; (veh = findflags(veh, vehicle_flags, VHF_ISVEHICLE)); )
2171 if(vlen(veh.origin - this.origin) < autocvar_g_vehicles_enter_radius)
2173 if(veh.takedamage != DAMAGE_NO)
2174 if((veh.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(veh.owner, this))
2175 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
2177 if(!veh.team || SAME_TEAM(this, veh))
2178 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER);
2179 else if(autocvar_g_vehicles_steal)
2180 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
2182 this.last_vehiclecheck = time + 1;
2185 if(!this.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2187 if(PHYS_INPUT_BUTTON_USE(this) && !this.usekeypressed)
2189 this.usekeypressed = PHYS_INPUT_BUTTON_USE(this);
2192 if (IS_REAL_CLIENT(this))
2193 PrintWelcomeMessage(this);
2195 if (IS_PLAYER(this)) {
2196 CheckRules_Player();
2198 if (intermission_running) {
2199 IntermissionThink();
2203 if (timeout_status == TIMEOUT_ACTIVE) {
2204 // don't allow the player to turn around while game is paused
2205 // FIXME turn this into CSQC stuff
2206 this.v_angle = this.lastV_angle;
2207 this.angles = this.lastV_angle;
2208 this.fixangle = true;
2211 if (frametime) player_powerups();
2213 if (IS_DEAD(this)) {
2214 if (this.personal && g_race_qualifying) {
2215 if (time > this.respawn_time) {
2216 STAT(RESPAWN_TIME, this) = this.respawn_time = time + 1; // only retry once a second
2218 this.impulse = CHIMPULSE_SPEEDRUN.impulse;
2221 if (frametime) player_anim();
2222 bool button_pressed = (PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_ATCK2(this) || PHYS_INPUT_BUTTON_HOOK(this) || PHYS_INPUT_BUTTON_USE(this));
2224 if (this.deadflag == DEAD_DYING) {
2225 if ((this.respawn_flags & RESPAWN_FORCE) && !autocvar_g_respawn_delay_max) {
2226 this.deadflag = DEAD_RESPAWNING;
2227 } else if (!button_pressed) {
2228 this.deadflag = DEAD_DEAD;
2230 } else if (this.deadflag == DEAD_DEAD) {
2231 if (button_pressed) {
2232 this.deadflag = DEAD_RESPAWNABLE;
2233 } else if (time >= this.respawn_time_max && (this.respawn_flags & RESPAWN_FORCE)) {
2234 this.deadflag = DEAD_RESPAWNING;
2236 } else if (this.deadflag == DEAD_RESPAWNABLE) {
2237 if (!button_pressed) {
2238 this.deadflag = DEAD_RESPAWNING;
2240 } else if (this.deadflag == DEAD_RESPAWNING) {
2241 if (time > this.respawn_time) {
2242 this.respawn_time = time + 1; // only retry once a second
2243 this.respawn_time_max = this.respawn_time;
2248 ShowRespawnCountdown();
2250 if (this.respawn_flags & RESPAWN_SILENT)
2251 STAT(RESPAWN_TIME, this) = 0;
2252 else if ((this.respawn_flags & RESPAWN_FORCE) && autocvar_g_respawn_delay_max)
2253 STAT(RESPAWN_TIME, this) = this.respawn_time_max;
2255 STAT(RESPAWN_TIME, this) = this.respawn_time;
2258 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2259 if (this.deadflag == DEAD_RESPAWNING && STAT(RESPAWN_TIME, this) > 0)
2260 STAT(RESPAWN_TIME, this) *= -1;
2265 this.prevorigin = this.origin;
2267 bool do_crouch = PHYS_INPUT_BUTTON_CROUCH(this);
2268 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
2269 if (this.hook.state) {
2271 } else if (this.vehicle) {
2273 } else if (STAT(FROZEN, this)) {
2275 } else if ((PS(this).m_weapon == WEP_SHOTGUN || PS(this).m_weapon == WEP_SHOCKWAVE) && this.(weaponentity).wframe == WFRAME_FIRE2 && time < this.(weaponentity).weapon_nextthink) {
2276 // WEAPONTODO: predict
2283 this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, this);
2284 setsize(this, STAT(PL_CROUCH_MIN, this), STAT(PL_CROUCH_MAX, this));
2285 // setanim(this, this.anim_duck, false, true, true); // this anim is BROKEN anyway
2287 } else if (this.crouch) {
2288 tracebox(this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), this.origin, false, this);
2289 if (!trace_startsolid) {
2290 this.crouch = false;
2291 this.view_ofs = STAT(PL_VIEW_OFS, this);
2292 setsize(this, STAT(PL_MIN, this), STAT(PL_MAX, this));
2296 FixPlayermodel(this);
2298 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2301 this.items &= ~this.items_added;
2303 W_WeaponFrame(this);
2305 this.items_added = 0;
2306 if (this.items & ITEM_Jetpack.m_itemid && (this.items & ITEM_JetpackRegen.m_itemid || this.ammo_fuel >= 0.01))
2307 this.items_added |= IT_FUEL;
2309 this.items |= this.items_added;
2314 // WEAPONTODO: Add a weapon request for this
2315 // rot vortex charge to the charge limit
2316 if (WEP_CVAR(vortex, charge_rot_rate) && this.vortex_charge > WEP_CVAR(vortex, charge_limit) && this.vortex_charge_rottime < time)
2317 this.vortex_charge = bound(WEP_CVAR(vortex, charge_limit), this.vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1);
2319 if (frametime) player_anim();
2322 secrets_setstatus();
2325 monsters_setstatus(this);
2327 this.dmg_team = max(0, this.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2329 else if (gameover) {
2330 if (intermission_running) IntermissionThink();
2333 else if (IS_OBSERVER(this)) {
2336 else if (IS_SPEC(this)) {
2340 // WEAPONTODO: Add weapon request for this
2341 if (!zoomstate_set) {
2343 PHYS_INPUT_BUTTON_ZOOM(this) || PHYS_INPUT_BUTTON_ZOOMSCRIPT(this)
2344 || (PHYS_INPUT_BUTTON_ATCK2(this) && PS(this).m_weapon == WEP_VORTEX)
2345 || (PHYS_INPUT_BUTTON_ATCK2(this) && PS(this).m_weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0)
2349 int oldspectatee_status = this.spectatee_status;
2350 if (IS_SPEC(this)) {
2351 this.spectatee_status = etof(this.enemy);
2352 } else if (IS_OBSERVER(this)) {
2353 this.spectatee_status = etof(this);
2355 this.spectatee_status = 0;
2357 if (this.spectatee_status != oldspectatee_status) {
2358 ClientData_Touch(this);
2359 if (g_race || g_cts) race_InitSpectator();
2362 if (this.teamkill_soundtime && time > this.teamkill_soundtime)
2364 this.teamkill_soundtime = 0;
2366 entity e = this.teamkill_soundsource;
2367 entity oldpusher = e.pusher;
2369 PlayerSound(e, playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2370 e.pusher = oldpusher;
2373 if (this.taunt_soundtime && time > this.taunt_soundtime) {
2374 this.taunt_soundtime = 0;
2375 PlayerSound(this, playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2378 target_voicescript_next(this);
2380 // WEAPONTODO: Move into weaponsystem somehow
2381 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2382 if (PS(this).m_weapon == WEP_Null)
2383 this.clip_load = this.clip_size = 0;
2386 void DrownPlayer(entity this)
2391 if (this.waterlevel != WATERLEVEL_SUBMERGED)
2393 if(this.air_finished < time)
2394 PlayerSound(this, playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
2395 this.air_finished = time + autocvar_g_balance_contents_drowndelay;
2398 else if (this.air_finished < time)
2400 if (this.pain_finished < time)
2402 Damage (this, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, this.origin, '0 0 0');
2403 this.pain_finished = time + 0.5;
2412 Called every frame for each client after the physics are run
2415 .float idlekick_lasttimeleft;
2416 void PlayerPostThink ()
2420 if (frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2421 if (IS_REAL_CLIENT(this))
2422 if (IS_PLAYER(this) || sv_maxidle_spectatorsareidle)
2424 if (time - this.parm_idlesince < 1) // instead of (time == this.parm_idlesince) to support sv_maxidle <= 10
2426 if (this.idlekick_lasttimeleft)
2428 this.idlekick_lasttimeleft = 0;
2429 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_IDLING);
2434 float timeleft = ceil(sv_maxidle - (time - this.parm_idlesince));
2435 if (timeleft == min(10, sv_maxidle - 1)) { // - 1 to support sv_maxidle <= 10
2436 if (!this.idlekick_lasttimeleft)
2437 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
2439 if (timeleft <= 0) {
2440 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_KICK_IDLING, this.netname);
2444 else if (timeleft <= 10) {
2445 if (timeleft != this.idlekick_lasttimeleft) {
2446 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, Announcer_PickNumber(CNT_IDLE, timeleft));
2448 this.idlekick_lasttimeleft = timeleft;
2455 //CheckPlayerJump();
2457 if (IS_PLAYER(this)) {
2459 CheckRules_Player();
2461 if (this.impulse) ImpulseCommands(this);
2462 if (intermission_running) return; // intermission or finale
2466 if (this.waypointsprite_attachedforcarrier) {
2467 vector v = healtharmor_maxdamage(this.health, this.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id);
2468 WaypointSprite_UpdateHealth(this.waypointsprite_attachedforcarrier, '1 0 0' * v);
2473 CSQCMODEL_AUTOUPDATE(this);