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(entity this);
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(e);
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(entity this)
189 bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver, this);
190 PlayerState_detach(this);
192 if (IS_PLAYER(this) && this.health >= 1) {
194 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
198 entity spot = SelectSpawnPoint(this, true);
199 if (!spot) LOG_FATAL("No spawnpoints for observers?!?");
200 this.angles = spot.angles;
202 this.fixangle = true;
203 // offset it so that the spectator spawns higher off the ground, looks better this way
204 setorigin(this, spot.origin + STAT(PL_VIEW_OFS, NULL));
205 this.prevorigin = this.origin;
206 if (IS_REAL_CLIENT(this))
209 WriteByte(MSG_ONE, SVC_SETVIEW);
210 WriteEntity(MSG_ONE, this);
212 // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
213 // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
214 if(!autocvar_g_debug_globalsounds)
216 // needed for player sounds
218 FixPlayermodel(this);
220 setmodel(this, MDL_Null);
221 setsize(this, STAT(PL_CROUCH_MIN, NULL), STAT(PL_CROUCH_MAX, NULL));
222 this.view_ofs = '0 0 0';
225 RemoveGrapplingHook(this);
226 Portal_ClearAll(this);
232 PS_GR_P_ADDVAL(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
236 if (this.vehicle) vehicles_exit(this.vehicle, VHEF_RELEASE);
238 WaypointSprite_PlayerDead(this);
240 if (mutator_returnvalue) {
241 // mutator prevents resetting teams+score
243 this.team = -1; // move this as it is needed to log the player spectating in eventlog
244 this.frags = FRAGS_SPECTATOR;
245 PlayerScore_Clear(this); // clear scores when needed
248 if (this.killcount != FRAGS_SPECTATOR)
250 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_SPECTATE, this.netname);
251 if(!intermission_running)
252 if(autocvar_g_chat_nospectators == 1 || (!(warmup_stage || gameover) && autocvar_g_chat_nospectators == 2))
253 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CHAT_NOSPECTATORS);
255 if(this.just_joined == false) {
256 LogTeamchange(this.playerid, -1, 4);
258 this.just_joined = false;
261 accuracy_resend(this);
263 this.spectatortime = time;
264 this.bot_attack = false;
265 this.hud = HUD_NORMAL;
266 TRANSMUTE(Observer, this);
267 this.iscreature = false;
268 this.teleportable = TELEPORT_SIMPLE;
269 this.damagedbycontents = false;
270 this.health = FRAGS_SPECTATOR;
271 this.takedamage = DAMAGE_NO;
272 this.solid = SOLID_NOT;
273 this.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink
274 this.flags = FL_CLIENT | FL_NOTARGET;
275 this.armorvalue = 666;
277 this.armorvalue = autocvar_g_balance_armor_start;
278 this.pauserotarmor_finished = 0;
279 this.pauserothealth_finished = 0;
280 this.pauseregen_finished = 0;
281 this.damageforcescale = 0;
283 this.respawn_flags = 0;
284 this.respawn_time = 0;
285 this.stat_respawn_time = 0;
290 this.pain_finished = 0;
291 this.strength_finished = 0;
292 this.invincible_finished = 0;
293 this.superweapons_finished = 0;
296 setthink(this, func_null);
299 this.deadflag = DEAD_NO;
301 this.revival_time = 0;
304 this.weapons = '0 0 0';
305 this.drawonlytoclient = this;
307 this.weaponname = "";
308 this.weaponmodel = "";
309 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
311 this.weaponentities[slot] = NULL;
313 this.exteriorweaponentity = NULL;
314 this.killcount = FRAGS_SPECTATOR;
315 this.velocity = '0 0 0';
316 this.avelocity = '0 0 0';
317 this.punchangle = '0 0 0';
318 this.punchvector = '0 0 0';
319 this.oldvelocity = this.velocity;
320 this.fire_endtime = -1;
321 this.event_damage = func_null;
324 int player_getspecies(entity this)
326 get_model_parameters(this.model, this.skin);
327 int s = get_model_parameters_species;
328 get_model_parameters(string_null, 0);
329 if (s < 0) return SPECIES_HUMAN;
333 .float model_randomizer;
334 void FixPlayermodel(entity player)
336 string defaultmodel = "";
338 if(autocvar_sv_defaultcharacter)
342 string s = Static_Team_ColorName_Lower(player.team);
345 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
346 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
350 if(defaultmodel == "")
352 defaultmodel = autocvar_sv_defaultplayermodel;
353 defaultskin = autocvar_sv_defaultplayerskin;
356 int n = tokenize_console(defaultmodel);
359 defaultmodel = argv(floor(n * player.model_randomizer));
360 // However, do NOT randomize if the player-selected model is in the list.
361 for (int i = 0; i < n; ++i)
362 if ((argv(i) == player.playermodel && defaultskin == stof(player.playerskin)) || argv(i) == strcat(player.playermodel, ":", player.playerskin))
363 defaultmodel = argv(i);
366 int i = strstrofs(defaultmodel, ":", 0);
369 defaultskin = stof(substring(defaultmodel, i+1, -1));
370 defaultmodel = substring(defaultmodel, 0, i);
373 if(autocvar_sv_defaultcharacterskin && !defaultskin)
377 string s = Static_Team_ColorName_Lower(player.team);
379 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
383 defaultskin = autocvar_sv_defaultplayerskin;
386 MUTATOR_CALLHOOK(FixPlayermodel, defaultmodel, defaultskin);
387 defaultmodel = M_ARGV(0, string);
388 defaultskin = M_ARGV(1, int);
392 if(defaultmodel != "")
394 if (defaultmodel != player.model)
396 vector m1 = player.mins;
397 vector m2 = player.maxs;
398 setplayermodel (player, defaultmodel);
399 setsize (player, m1, m2);
403 oldskin = player.skin;
404 player.skin = defaultskin;
406 if (player.playermodel != player.model || player.playermodel == "")
408 player.playermodel = CheckPlayerModel(player.playermodel); // this is never "", so no endless loop
409 vector m1 = player.mins;
410 vector m2 = player.maxs;
411 setplayermodel (player, player.playermodel);
412 setsize (player, m1, m2);
416 if(!autocvar_sv_defaultcharacterskin)
418 oldskin = player.skin;
419 player.skin = stof(player.playerskin);
423 oldskin = player.skin;
424 player.skin = defaultskin;
428 if(chmdl || oldskin != player.skin) // model or skin has changed
430 player.species = player_getspecies(player); // update species
431 if(!autocvar_g_debug_globalsounds)
432 UpdatePlayerSounds(player); // update skin sounds
436 if(strlen(autocvar_sv_defaultplayercolors))
437 if(player.clientcolors != stof(autocvar_sv_defaultplayercolors))
438 setcolor(player, stof(autocvar_sv_defaultplayercolors));
442 /** Called when a client spawns in the server */
443 void PutClientInServer()
445 SELFPARAM(); // needed for engine functions
446 if (IS_BOT_CLIENT(this)) {
447 TRANSMUTE(Player, this);
448 } else if (IS_REAL_CLIENT(this)) {
450 WriteByte(MSG_ONE, SVC_SETVIEW);
451 WriteEntity(MSG_ONE, this);
454 TRANSMUTE(Observer, this);
457 SetSpectatee(this, NULL);
462 MUTATOR_CALLHOOK(PutClientInServer, this);
464 if (IS_OBSERVER(this)) {
465 PutObserverInServer(this);
466 } else if (IS_PLAYER(this)) {
467 PlayerState_attach(this);
468 accuracy_resend(this);
471 JoinBestTeam(this, false, true);
473 entity spot = SelectSpawnPoint(this, false);
475 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
476 return; // spawn failed
479 TRANSMUTE(Player, this);
480 this.wasplayer = true;
481 this.iscreature = true;
482 this.teleportable = TELEPORT_NORMAL;
483 this.damagedbycontents = true;
484 this.movetype = MOVETYPE_WALK;
485 this.solid = SOLID_SLIDEBOX;
486 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
487 if (autocvar_g_playerclip_collisions)
488 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
489 if (IS_BOT_CLIENT(this) && autocvar_g_botclip_collisions)
490 this.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
491 this.frags = FRAGS_PLAYER;
492 if (INDEPENDENT_PLAYERS) MAKE_INDEPENDENT_PLAYER(this);
493 this.flags = FL_CLIENT | FL_PICKUPITEMS;
494 if (autocvar__notarget)
495 this.flags |= FL_NOTARGET;
496 this.takedamage = DAMAGE_AIM;
497 this.effects = EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
501 this.ammo_shells = warmup_start_ammo_shells;
502 this.ammo_nails = warmup_start_ammo_nails;
503 this.ammo_rockets = warmup_start_ammo_rockets;
504 this.ammo_cells = warmup_start_ammo_cells;
505 this.ammo_plasma = warmup_start_ammo_plasma;
506 this.ammo_fuel = warmup_start_ammo_fuel;
507 this.health = warmup_start_health;
508 this.armorvalue = warmup_start_armorvalue;
509 this.weapons = WARMUP_START_WEAPONS;
511 this.ammo_shells = start_ammo_shells;
512 this.ammo_nails = start_ammo_nails;
513 this.ammo_rockets = start_ammo_rockets;
514 this.ammo_cells = start_ammo_cells;
515 this.ammo_plasma = start_ammo_plasma;
516 this.ammo_fuel = start_ammo_fuel;
517 this.health = start_health;
518 this.armorvalue = start_armorvalue;
519 this.weapons = start_weapons;
522 this.superweapons_finished = (this.weapons & WEPSET_SUPERWEAPONS) ? time + autocvar_g_balance_superweapons_time : 0;
524 this.items = start_items;
526 this.spawnshieldtime = time + autocvar_g_spawnshieldtime;
527 this.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
528 this.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
529 this.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
530 this.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
531 // extend the pause of rotting if client was reset at the beginning of the countdown
532 if (!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
533 float f = game_starttime - time;
534 this.spawnshieldtime += f;
535 this.pauserotarmor_finished += f;
536 this.pauserothealth_finished += f;
537 this.pauseregen_finished += f;
539 this.damageforcescale = 2;
541 this.respawn_flags = 0;
542 this.respawn_time = 0;
543 this.stat_respawn_time = 0;
544 this.scale = autocvar_sv_player_scale;
547 this.pain_finished = 0;
549 setthink(this, func_null); // players have no think function
552 this.ballistics_density = autocvar_g_ballistics_density_player;
554 this.deadflag = DEAD_NO;
556 this.angles = spot.angles;
557 this.angles_z = 0; // never spawn tilted even if the spot says to
558 if (IS_BOT_CLIENT(this))
559 this.v_angle = this.angles;
560 this.fixangle = true; // turn this way immediately
561 this.oldvelocity = this.velocity = '0 0 0';
562 this.avelocity = '0 0 0';
563 this.punchangle = '0 0 0';
564 this.punchvector = '0 0 0';
566 this.strength_finished = 0;
567 this.invincible_finished = 0;
568 this.fire_endtime = -1;
569 this.revival_time = 0;
570 this.air_finished = time + 12;
572 entity spawnevent = new_pure(spawnevent);
573 spawnevent.owner = this;
574 Net_LinkEntity(spawnevent, false, 0.5, SpawnEvent_Send);
576 // Cut off any still running player sounds.
577 stopsound(this, CH_PLAYER_SINGLE);
580 FixPlayermodel(this);
581 this.drawonlytoclient = NULL;
584 this.view_ofs = STAT(PL_VIEW_OFS, NULL);
585 setsize(this, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
586 this.spawnorigin = spot.origin;
587 setorigin(this, spot.origin + '0 0 1' * (1 - this.mins.z - 24));
588 // don't reset back to last position, even if new position is stuck in solid
589 this.oldorigin = this.origin;
590 this.prevorigin = this.origin;
591 this.lastteleporttime = time; // prevent insane speeds due to changing origin
592 this.conveyor = NULL; // prevent conveyors at the previous location from moving a freshly spawned player
593 this.hud = HUD_NORMAL;
595 this.event_damage = PlayerDamage;
597 this.bot_attack = true;
598 this.monster_attack = true;
600 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_JUMP(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
602 if (this.killcount == FRAGS_SPECTATOR) {
603 PlayerScore_Clear(this);
607 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
609 CL_SpawnWeaponentity(this, weaponentities[slot]);
611 this.alpha = default_player_alpha;
612 this.colormod = '1 1 1' * autocvar_g_player_brightness;
613 this.exteriorweaponentity.alpha = default_weapon_alpha;
615 this.speedrunning = false;
617 target_voicescript_clear(this);
619 // reset fields the weapons may use
620 FOREACH(Weapons, true, LAMBDA(
621 it.wr_resetplayer(it, this);
622 // reload all reloadable weapons
623 if (it.spawnflags & WEP_FLAG_RELOADABLE) {
624 this.weapon_load[it.m_id] = it.reloading_ammo;
629 string s = spot.target;
630 spot.target = string_null;
631 SUB_UseTargets(spot, this, NULL);
637 MUTATOR_CALLHOOK(PlayerSpawn, this, spot);
639 if (autocvar_spawn_debug)
641 sprint(this, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
642 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
645 PS(this).m_switchweapon = w_getbestweapon(this);
646 this.cnt = -1; // W_LastWeapon will not complain
647 PS(this).m_weapon = WEP_Null;
648 this.weaponname = "";
649 PS(this).m_switchingweapon = WEP_Null;
651 if (!warmup_stage && !this.alivetime)
652 this.alivetime = time;
654 antilag_clear(this, CS(this));
658 void ClientInit_misc(entity this);
660 .float ebouncefactor, ebouncestop; // electro's values
661 // TODO do we need all these fields, or should we stop autodetecting runtime
662 // changes and just have a console command to update this?
663 bool ClientInit_SendEntity(entity this, entity to, int sf)
665 WriteHeader(MSG_ENTITY, _ENT_CLIENT_INIT);
668 // MSG_INIT replacement
669 // TODO: make easier to use
671 W_PROP_reload(MSG_ONE, to);
672 ClientInit_misc(this);
673 MUTATOR_CALLHOOK(Ent_Init);
675 void ClientInit_misc(entity this)
677 int channel = MSG_ONE;
678 WriteHeader(channel, ENT_CLIENT_INIT);
679 WriteByte(channel, g_nexball_meter_period * 32);
680 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[0]));
681 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[1]));
682 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[2]));
683 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[3]));
684 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[0]));
685 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[1]));
686 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[2]));
687 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[3]));
689 if(sv_foginterval && world.fog != "")
690 WriteString(channel, world.fog);
692 WriteString(channel, "");
693 WriteByte(channel, this.count * 255.0); // g_balance_armor_blockpercent
694 WriteByte(channel, serverflags); // client has to know if it should zoom or not
695 WriteCoord(channel, autocvar_g_trueaim_minrange);
698 void ClientInit_CheckUpdate(entity this)
700 this.nextthink = time;
701 if(this.count != autocvar_g_balance_armor_blockpercent)
703 this.count = autocvar_g_balance_armor_blockpercent;
708 void ClientInit_Spawn()
710 entity e = new_pure(clientinit);
711 setthink(e, ClientInit_CheckUpdate);
712 Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
714 WITHSELF(e, ClientInit_CheckUpdate(e));
724 // initialize parms for a new player
725 parm1 = -(86400 * 366);
727 MUTATOR_CALLHOOK(SetNewParms);
735 void SetChangeParms ()
736 {SELFPARAM(); // needed for engine functions
737 // save parms for level change
738 parm1 = this.parm_idlesince - time;
740 MUTATOR_CALLHOOK(SetChangeParms);
748 void DecodeLevelParms(entity this)
751 this.parm_idlesince = parm1;
752 if (this.parm_idlesince == -(86400 * 366))
753 this.parm_idlesince = time;
755 // whatever happens, allow 60 seconds of idling directly after connect for map loading
756 this.parm_idlesince = max(this.parm_idlesince, time - sv_maxidle + 60);
758 MUTATOR_CALLHOOK(DecodeLevelParms);
765 Called when a client types 'kill' in the console
769 .float clientkill_nexttime;
770 void ClientKill_Now_TeamChange(entity this)
772 if(this.killindicator_teamchange == -1)
774 JoinBestTeam( this, false, true );
776 else if(this.killindicator_teamchange == -2)
779 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
780 PutObserverInServer(this);
783 WITHSELF(this, SV_ChangeTeam(this.killindicator_teamchange - 1));
784 this.killindicator_teamchange = 0;
787 void ClientKill_Now(entity this)
791 vehicles_exit(this.vehicle, VHEF_RELEASE);
792 if(!this.killindicator_teamchange)
794 this.vehicle_health = -1;
795 Damage(this, this, this, 1 , DEATH_KILL.m_id, this.origin, '0 0 0');
799 if(this.killindicator && !wasfreed(this.killindicator))
800 remove(this.killindicator);
802 this.killindicator = world;
804 if(this.killindicator_teamchange)
805 ClientKill_Now_TeamChange(this);
808 Damage(this, this, this, 100000, DEATH_KILL.m_id, this.origin, '0 0 0');
810 // now I am sure the player IS dead
812 void KillIndicator_Think(entity this)
816 this.owner.killindicator = world;
821 if (this.owner.alpha < 0 && !this.owner.vehicle)
823 this.owner.killindicator = world;
830 ClientKill_Now(this.owner);
833 else if(g_cts && this.health == 1) // health == 1 means that it's silent
835 this.nextthink = time + 1;
841 setmodel(this, MDL_NUM(this.cnt));
842 if(IS_REAL_CLIENT(this.owner))
845 { Send_Notification(NOTIF_ONE, this.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, this.cnt)); }
847 this.nextthink = time + 1;
852 float clientkilltime;
853 void ClientKill_TeamChange (entity this, float targetteam) // 0 = don't change, -1 = auto, -2 = spec
862 killtime = autocvar_g_balance_kill_delay;
864 if(g_race_qualifying || g_cts)
867 if(MUTATOR_CALLHOOK(ClientKill, this, killtime))
870 this.killindicator_teamchange = targetteam;
872 if(!this.killindicator)
876 killtime = max(killtime, this.clientkill_nexttime - time);
877 this.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
880 if(killtime <= 0 || !IS_PLAYER(this) || IS_DEAD(this))
882 ClientKill_Now(this);
886 starttime = max(time, clientkilltime);
888 this.killindicator = spawn();
889 this.killindicator.owner = this;
890 this.killindicator.scale = 0.5;
891 setattachment(this.killindicator, this, "");
892 setorigin(this.killindicator, '0 0 52');
893 setthink(this.killindicator, KillIndicator_Think);
894 this.killindicator.nextthink = starttime + (this.lip) * 0.05;
895 clientkilltime = max(clientkilltime, this.killindicator.nextthink + 0.05);
896 this.killindicator.cnt = ceil(killtime);
897 this.killindicator.count = bound(0, ceil(killtime), 10);
898 //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
900 for(e = world; (e = find(e, classname, "body")) != world; )
904 e.killindicator = spawn();
905 e.killindicator.owner = e;
906 e.killindicator.scale = 0.5;
907 setattachment(e.killindicator, e, "");
908 setorigin(e.killindicator, '0 0 52');
909 setthink(e.killindicator, KillIndicator_Think);
910 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
911 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
912 e.killindicator.cnt = ceil(killtime);
917 if(this.killindicator)
919 if(targetteam == 0) // just die
921 this.killindicator.colormod = '0 0 0';
922 if(IS_REAL_CLIENT(this))
923 if(this.killindicator.cnt > 0)
924 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, this.killindicator.cnt);
926 else if(targetteam == -1) // auto
928 this.killindicator.colormod = '0 1 0';
929 if(IS_REAL_CLIENT(this))
930 if(this.killindicator.cnt > 0)
931 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, this.killindicator.cnt);
933 else if(targetteam == -2) // spectate
935 this.killindicator.colormod = '0.5 0.5 0.5';
936 if(IS_REAL_CLIENT(this))
937 if(this.killindicator.cnt > 0)
938 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, this.killindicator.cnt);
942 this.killindicator.colormod = Team_ColorRGB(targetteam);
943 if(IS_REAL_CLIENT(this))
944 if(this.killindicator.cnt > 0)
945 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE), this.killindicator.cnt);
952 {SELFPARAM(); // needed for engine functions
954 if(this.player_blocked) return;
955 if(STAT(FROZEN, this)) return;
957 ClientKill_TeamChange(this, 0);
960 void FixClientCvars(entity e)
962 // send prediction settings to the client
963 stuffcmd(e, "\nin_bindmap 0 0\n");
964 if(autocvar_g_antilag == 3) // client side hitscan
965 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
966 if(autocvar_sv_gentle)
967 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
969 MUTATOR_CALLHOOK(FixClientCvars, e);
972 float PlayerInIDList(entity p, string idlist)
977 // NOTE: we do NOT check crypto_idfp_signed here, an unsigned ID is fine too for this
981 // this function allows abbreviated player IDs too!
982 n = tokenize_console(idlist);
983 for(i = 0; i < n; ++i)
986 if(s == substring(p.crypto_idfp, 0, strlen(s)))
993 #ifdef DP_EXT_PRECONNECT
998 Called once (not at each match start) when a client begins a connection to the server
1001 void ClientPreConnect ()
1002 {SELFPARAM(); // needed for engine functions
1003 if(autocvar_sv_eventlog)
1005 GameLogEcho(sprintf(":connect:%d:%d:%s",
1008 ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot")
1018 Called when a client connects to the server
1021 void ClientConnect()
1023 SELFPARAM(); // needed for engine functions
1024 if (Ban_MaybeEnforceBanOnce(this)) return;
1025 assert(!IS_CLIENT(this), return);
1026 this.flags |= FL_CLIENT;
1027 assert(player_count >= 0, player_count = 0);
1030 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_WATERMARK, WATERMARK);
1032 this.version_nagtime = time + 10 + random() * 10;
1033 TRANSMUTE(Client, this);
1035 // identify the right forced team
1036 if (autocvar_g_campaign)
1038 if (IS_REAL_CLIENT(this)) // only players, not bots
1040 switch (autocvar_g_campaign_forceteam)
1042 case 1: this.team_forced = NUM_TEAM_1; break;
1043 case 2: this.team_forced = NUM_TEAM_2; break;
1044 case 3: this.team_forced = NUM_TEAM_3; break;
1045 case 4: this.team_forced = NUM_TEAM_4; break;
1046 default: this.team_forced = 0;
1050 else if (PlayerInIDList(this, autocvar_g_forced_team_red)) this.team_forced = NUM_TEAM_1;
1051 else if (PlayerInIDList(this, autocvar_g_forced_team_blue)) this.team_forced = NUM_TEAM_2;
1052 else if (PlayerInIDList(this, autocvar_g_forced_team_yellow)) this.team_forced = NUM_TEAM_3;
1053 else if (PlayerInIDList(this, autocvar_g_forced_team_pink)) this.team_forced = NUM_TEAM_4;
1054 else switch (autocvar_g_forced_team_otherwise)
1056 default: this.team_forced = 0; break;
1057 case "red": this.team_forced = NUM_TEAM_1; break;
1058 case "blue": this.team_forced = NUM_TEAM_2; break;
1059 case "yellow": this.team_forced = NUM_TEAM_3; break;
1060 case "pink": this.team_forced = NUM_TEAM_4; break;
1063 this.team_forced = -1;
1066 if (!teamplay && this.team_forced > 0) this.team_forced = 0;
1069 int id = this.playerid;
1070 this.playerid = 0; // silent
1071 JoinBestTeam(this, false, false); // if the team number is valid, keep it
1075 if (autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) {
1076 TRANSMUTE(Observer, this);
1078 if (!teamplay || autocvar_g_balance_teams) {
1079 TRANSMUTE(Player, this);
1080 campaign_bots_may_start = true;
1082 TRANSMUTE(Observer, this); // do it anyway
1086 PlayerStats_GameReport_AddEvent(sprintf("kills-%d", this.playerid));
1088 // always track bots, don't ask for cl_allow_uidtracking
1089 if (IS_BOT_CLIENT(this)) PlayerStats_GameReport_AddPlayer(this);
1091 if (autocvar_sv_eventlog)
1092 GameLogEcho(strcat(":join:", ftos(this.playerid), ":", ftos(etof(this)), ":", ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot"), ":", this.netname));
1094 LogTeamchange(this.playerid, this.team, 1);
1096 this.just_joined = true; // stop spamming the eventlog with additional lines when the client connects
1098 this.netname_previous = strzone(this.netname);
1100 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && IS_PLAYER(this)) ? APP_TEAM_ENT(this, INFO_JOIN_CONNECT_TEAM) : INFO_JOIN_CONNECT), this.netname);
1102 stuffcmd(this, clientstuff, "\n");
1103 stuffcmd(this, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1105 FixClientCvars(this);
1107 // get version info from player
1108 stuffcmd(this, "cmd clientversion $gameversion\n");
1110 // notify about available teams
1113 CheckAllowedTeams(this);
1115 if (c1 >= 0) t |= BIT(0);
1116 if (c2 >= 0) t |= BIT(1);
1117 if (c3 >= 0) t |= BIT(2);
1118 if (c4 >= 0) t |= BIT(3);
1119 stuffcmd(this, sprintf("set _teams_available %d\n", t));
1123 stuffcmd(this, "set _teams_available 0\n");
1126 bot_relinkplayerlist();
1128 this.spectatortime = time;
1129 if (blockSpectators)
1131 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1134 this.jointime = time;
1135 this.allowed_timeouts = autocvar_sv_timeout_number;
1137 if (IS_REAL_CLIENT(this))
1139 if (!autocvar_g_campaign)
1141 this.motd_actived_time = -1;
1142 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage(this));
1145 if (g_weaponarena_weapons == WEPSET(TUBA))
1146 stuffcmd(this, "cl_cmd settemp chase_active 1\n");
1149 if (!sv_foginterval && world.fog != "")
1150 stuffcmd(this, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1152 if (autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)))
1153 if (!g_ca && !g_cts && !g_race) // teamnagger is currently bad for ca, race & cts
1154 send_CSQC_teamnagger();
1156 CSQCMODEL_AUTOINIT(this);
1158 this.model_randomizer = random();
1160 if (IS_REAL_CLIENT(this))
1161 sv_notice_join(this);
1163 FOREACH_ENTITY_FLOAT(init_for_player_needed, true, {
1164 it.init_for_player(it, this);
1167 MUTATOR_CALLHOOK(ClientConnect, this);
1173 Called when a client disconnects from the server
1176 .entity chatbubbleentity;
1178 void ClientDisconnect()
1180 SELFPARAM(); // needed for engine functions
1181 assert(IS_CLIENT(this), return);
1183 PlayerStats_GameReport_FinalizePlayer(this);
1184 if (this.vehicle) vehicles_exit(this.vehicle, VHEF_RELEASE);
1185 if (this.active_minigame) part_minigame(this);
1186 if (IS_PLAYER(this)) Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
1188 if (autocvar_sv_eventlog)
1189 GameLogEcho(strcat(":part:", ftos(this.playerid)));
1191 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
1193 MUTATOR_CALLHOOK(ClientDisconnect, this);
1195 ClientState_detach(this);
1197 Portal_ClearAll(this);
1201 RemoveGrapplingHook(this);
1203 // Here, everything has been done that requires this player to be a client.
1205 this.flags &= ~FL_CLIENT;
1207 if (this.chatbubbleentity) remove(this.chatbubbleentity);
1208 if (this.killindicator) remove(this.killindicator);
1210 WaypointSprite_PlayerGone(this);
1212 bot_relinkplayerlist();
1214 if (this.netname_previous) strunzone(this.netname_previous);
1215 if (this.clientstatus) strunzone(this.clientstatus);
1216 if (this.weaponorder_byimpulse) strunzone(this.weaponorder_byimpulse);
1217 if (this.personal) remove(this.personal);
1221 if (vote_called && IS_REAL_CLIENT(this)) VoteCount(false);
1224 void ChatBubbleThink(entity this)
1226 this.nextthink = time;
1227 if ((this.owner.alpha < 0) || this.owner.chatbubbleentity != this)
1229 if(this.owner) // but why can that ever be world?
1230 this.owner.chatbubbleentity = world;
1237 if ( !IS_DEAD(this.owner) && IS_PLAYER(this.owner) )
1239 if ( this.owner.active_minigame )
1240 this.mdl = "models/sprites/minigame_busy.iqm";
1241 else if (PHYS_INPUT_BUTTON_CHAT(this.owner))
1242 this.mdl = "models/misc/chatbubble.spr";
1245 if ( this.model != this.mdl )
1246 _setmodel(this, this.mdl);
1250 void UpdateChatBubble(entity this)
1254 // spawn a chatbubble entity if needed
1255 if (!this.chatbubbleentity)
1257 this.chatbubbleentity = new(chatbubbleentity);
1258 this.chatbubbleentity.owner = this;
1259 this.chatbubbleentity.exteriormodeltoclient = this;
1260 setthink(this.chatbubbleentity, ChatBubbleThink);
1261 this.chatbubbleentity.nextthink = time;
1262 setmodel(this.chatbubbleentity, MDL_CHAT); // precision set below
1263 //setorigin(this.chatbubbleentity, this.origin + '0 0 15' + this.maxs_z * '0 0 1');
1264 setorigin(this.chatbubbleentity, '0 0 15' + this.maxs_z * '0 0 1');
1265 setattachment(this.chatbubbleentity, this, ""); // sticks to moving player better, also conserves bandwidth
1266 this.chatbubbleentity.mdl = this.chatbubbleentity.model;
1267 //this.chatbubbleentity.model = "";
1268 this.chatbubbleentity.effects = EF_LOWPRECISION;
1273 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1274 // added to the model skins
1275 /*void UpdateColorModHack()
1278 c = this.clientcolors & 15;
1279 // LordHavoc: only bothering to support white, green, red, yellow, blue
1280 if (!teamplay) this.colormod = '0 0 0';
1281 else if (c == 0) this.colormod = '1.00 1.00 1.00';
1282 else if (c == 3) this.colormod = '0.10 1.73 0.10';
1283 else if (c == 4) this.colormod = '1.73 0.10 0.10';
1284 else if (c == 12) this.colormod = '1.22 1.22 0.10';
1285 else if (c == 13) this.colormod = '0.10 0.10 1.73';
1286 else this.colormod = '1 1 1';
1289 void respawn(entity this)
1291 if(this.alpha >= 0 && autocvar_g_respawn_ghosts)
1293 this.solid = SOLID_NOT;
1294 this.takedamage = DAMAGE_NO;
1295 this.movetype = MOVETYPE_FLY;
1296 this.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1297 this.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1298 this.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1299 Send_Effect(EFFECT_RESPAWN_GHOST, this.origin, '0 0 0', 1);
1300 if(autocvar_g_respawn_ghosts_maxtime)
1301 SUB_SetFade (this, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1306 this.effects |= EF_NODRAW; // prevent another CopyBody
1307 PutClientInServer();
1310 void play_countdown(entity this, float finished, Sound samp)
1313 if(IS_REAL_CLIENT(this))
1314 if(floor(finished - time - frametime) != floor(finished - time))
1315 if(finished - time < 6)
1316 sound (this, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
1319 void player_powerups(entity this)
1321 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1322 int items_prev = this.items;
1324 if((this.items & IT_USING_JETPACK) && !IS_DEAD(this) && !gameover)
1325 this.modelflags |= MF_ROCKET;
1327 this.modelflags &= ~MF_ROCKET;
1329 this.effects &= ~(EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1331 if((this.alpha < 0 || IS_DEAD(this)) && !this.vehicle) // don't apply the flags if the player is gibbed
1334 Fire_ApplyDamage(this);
1335 Fire_ApplyEffect(this);
1339 if (this.items & ITEM_Strength.m_itemid)
1341 play_countdown(this, this.strength_finished, SND_POWEROFF);
1342 this.effects = this.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1343 if (time > this.strength_finished)
1345 this.items = this.items - (this.items & ITEM_Strength.m_itemid);
1346 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, this.netname);
1347 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
1352 if (time < this.strength_finished)
1354 this.items = this.items | ITEM_Strength.m_itemid;
1355 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, this.netname);
1356 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERUP_STRENGTH);
1359 if (this.items & ITEM_Shield.m_itemid)
1361 play_countdown(this, this.invincible_finished, SND_POWEROFF);
1362 this.effects = this.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1363 if (time > this.invincible_finished)
1365 this.items = this.items - (this.items & ITEM_Shield.m_itemid);
1366 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, this.netname);
1367 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
1372 if (time < this.invincible_finished)
1374 this.items = this.items | ITEM_Shield.m_itemid;
1375 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, this.netname);
1376 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERUP_SHIELD);
1379 if (this.items & IT_SUPERWEAPON)
1381 if (!(this.weapons & WEPSET_SUPERWEAPONS))
1383 this.superweapons_finished = 0;
1384 this.items = this.items - (this.items & IT_SUPERWEAPON);
1385 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, this.netname);
1386 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1388 else if (this.items & IT_UNLIMITED_SUPERWEAPONS)
1390 // don't let them run out
1394 play_countdown(this, this.superweapons_finished, SND_POWEROFF);
1395 if (time > this.superweapons_finished)
1397 this.items = this.items - (this.items & IT_SUPERWEAPON);
1398 this.weapons &= ~WEPSET_SUPERWEAPONS;
1399 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, this.netname);
1400 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1404 else if(this.weapons & WEPSET_SUPERWEAPONS)
1406 if (time < this.superweapons_finished || (this.items & IT_UNLIMITED_SUPERWEAPONS))
1408 this.items = this.items | IT_SUPERWEAPON;
1409 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, this.netname);
1410 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1414 this.superweapons_finished = 0;
1415 this.weapons &= ~WEPSET_SUPERWEAPONS;
1420 this.superweapons_finished = 0;
1424 if(autocvar_g_nodepthtestplayers)
1425 this.effects = this.effects | EF_NODEPTHTEST;
1427 if(autocvar_g_fullbrightplayers)
1428 this.effects = this.effects | EF_FULLBRIGHT;
1430 if (time >= game_starttime)
1431 if (time < this.spawnshieldtime)
1432 this.effects = this.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1434 MUTATOR_CALLHOOK(PlayerPowerups, this, items_prev);
1437 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1439 if(current > stable)
1441 else if(current > stable - 0.25) // when close enough, "snap"
1444 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1447 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1449 if(current < stable)
1451 else if(current < stable + 0.25) // when close enough, "snap"
1454 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1457 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1459 if(current > rotstable)
1461 if(rotframetime > 0)
1463 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1464 current = max(rotstable, current - rotlinear * rotframetime);
1467 else if(current < regenstable)
1469 if(regenframetime > 0)
1471 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1472 current = min(regenstable, current + regenlinear * regenframetime);
1482 void player_regen(entity this)
1484 float max_mod, regen_mod, rot_mod, limit_mod;
1485 max_mod = regen_mod = rot_mod = limit_mod = 1;
1486 regen_mod_max = max_mod;
1487 regen_mod_regen = regen_mod;
1488 regen_mod_rot = rot_mod;
1489 regen_mod_limit = limit_mod;
1491 regen_health = autocvar_g_balance_health_regen;
1492 regen_health_linear = autocvar_g_balance_health_regenlinear;
1493 regen_health_rot = autocvar_g_balance_health_rot;
1494 regen_health_rotlinear = autocvar_g_balance_health_rotlinear;
1495 regen_health_stable = autocvar_g_balance_health_regenstable;
1496 regen_health_rotstable = autocvar_g_balance_health_rotstable;
1497 if(!MUTATOR_CALLHOOK(PlayerRegen))
1498 if(!STAT(FROZEN, this))
1500 float mina, maxa, limith, limita;
1501 maxa = autocvar_g_balance_armor_rotstable;
1502 mina = autocvar_g_balance_armor_regenstable;
1503 limith = autocvar_g_balance_health_limit;
1504 limita = autocvar_g_balance_armor_limit;
1506 max_mod = regen_mod_max;
1507 regen_mod = regen_mod_regen;
1508 rot_mod = regen_mod_rot;
1509 limit_mod = regen_mod_limit;
1511 regen_health_rotstable = regen_health_rotstable * max_mod;
1512 regen_health_stable = regen_health_stable * max_mod;
1513 limith = limith * limit_mod;
1514 limita = limita * limit_mod;
1516 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);
1517 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);
1520 // if player rotted to death... die!
1521 // check this outside above checks, as player may still be able to rot to death
1525 vehicles_exit(this.vehicle, VHEF_RELEASE);
1526 if(this.event_damage)
1527 this.event_damage(this, this, this, 1, DEATH_ROT.m_id, this.origin, '0 0 0');
1530 if (!(this.items & IT_UNLIMITED_WEAPON_AMMO))
1532 float minf, maxf, limitf;
1534 maxf = autocvar_g_balance_fuel_rotstable;
1535 minf = autocvar_g_balance_fuel_regenstable;
1536 limitf = autocvar_g_balance_fuel_limit;
1538 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);
1543 void SetZoomState(entity this, float z)
1545 if(z != this.zoomstate)
1548 ClientData_Touch(this);
1550 zoomstate_set = true;
1553 void GetPressedKeys(entity this)
1555 MUTATOR_CALLHOOK(GetPressedKeys, this);
1556 int keys = this.pressedkeys;
1557 keys = BITSET(keys, KEY_FORWARD, this.movement.x > 0);
1558 keys = BITSET(keys, KEY_BACKWARD, this.movement.x < 0);
1559 keys = BITSET(keys, KEY_RIGHT, this.movement.y > 0);
1560 keys = BITSET(keys, KEY_LEFT, this.movement.y < 0);
1562 keys = BITSET(keys, KEY_JUMP, PHYS_INPUT_BUTTON_JUMP(this));
1563 keys = BITSET(keys, KEY_CROUCH, PHYS_INPUT_BUTTON_CROUCH(this));
1564 keys = BITSET(keys, KEY_ATCK, PHYS_INPUT_BUTTON_ATCK(this));
1565 keys = BITSET(keys, KEY_ATCK2, PHYS_INPUT_BUTTON_ATCK2(this));
1566 this.pressedkeys = keys;
1570 ======================
1571 spectate mode routines
1572 ======================
1575 void SpectateCopy(entity this, entity spectatee)
1577 TC(Client, this); TC(Client, spectatee);
1579 MUTATOR_CALLHOOK(SpectateCopy, spectatee, this);
1580 PS(this) = PS(spectatee);
1581 this.armortype = spectatee.armortype;
1582 this.armorvalue = spectatee.armorvalue;
1583 this.ammo_cells = spectatee.ammo_cells;
1584 this.ammo_plasma = spectatee.ammo_plasma;
1585 this.ammo_shells = spectatee.ammo_shells;
1586 this.ammo_nails = spectatee.ammo_nails;
1587 this.ammo_rockets = spectatee.ammo_rockets;
1588 this.ammo_fuel = spectatee.ammo_fuel;
1589 this.clip_load = spectatee.clip_load;
1590 this.clip_size = spectatee.clip_size;
1591 this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1592 this.health = spectatee.health;
1594 this.items = spectatee.items;
1595 this.last_pickup = spectatee.last_pickup;
1596 this.hit_time = spectatee.hit_time;
1597 this.strength_finished = spectatee.strength_finished;
1598 this.invincible_finished = spectatee.invincible_finished;
1599 this.pressedkeys = spectatee.pressedkeys;
1600 this.weapons = spectatee.weapons;
1601 this.vortex_charge = spectatee.vortex_charge;
1602 this.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
1603 this.hagar_load = spectatee.hagar_load;
1604 this.arc_heat_percent = spectatee.arc_heat_percent;
1605 this.minelayer_mines = spectatee.minelayer_mines;
1606 this.punchangle = spectatee.punchangle;
1607 this.view_ofs = spectatee.view_ofs;
1608 this.velocity = spectatee.velocity;
1609 this.dmg_take = spectatee.dmg_take;
1610 this.dmg_save = spectatee.dmg_save;
1611 this.dmg_inflictor = spectatee.dmg_inflictor;
1612 this.v_angle = spectatee.v_angle;
1613 this.angles = spectatee.v_angle;
1614 STAT(FROZEN, this) = STAT(FROZEN, spectatee);
1615 this.revive_progress = spectatee.revive_progress;
1616 if(!PHYS_INPUT_BUTTON_USE(this))
1617 this.fixangle = true;
1618 setorigin(this, spectatee.origin);
1619 setsize(this, spectatee.mins, spectatee.maxs);
1620 SetZoomState(this, spectatee.zoomstate);
1622 anticheat_spectatecopy(this, spectatee);
1623 this.hud = spectatee.hud;
1624 if(spectatee.vehicle)
1626 this.fixangle = false;
1627 //this.velocity = spectatee.vehicle.velocity;
1628 this.vehicle_health = spectatee.vehicle_health;
1629 this.vehicle_shield = spectatee.vehicle_shield;
1630 this.vehicle_energy = spectatee.vehicle_energy;
1631 this.vehicle_ammo1 = spectatee.vehicle_ammo1;
1632 this.vehicle_ammo2 = spectatee.vehicle_ammo2;
1633 this.vehicle_reload1 = spectatee.vehicle_reload1;
1634 this.vehicle_reload2 = spectatee.vehicle_reload2;
1638 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1639 WriteAngle(MSG_ONE, spectatee.v_angle.x);
1640 WriteAngle(MSG_ONE, spectatee.v_angle.y);
1641 WriteAngle(MSG_ONE, spectatee.v_angle.z);
1643 //WriteByte (MSG_ONE, SVC_SETVIEW);
1644 // WriteEntity(MSG_ONE, this);
1645 //makevectors(spectatee.v_angle);
1646 //setorigin(this, spectatee.origin - v_forward * 400 + v_up * 300);*/
1650 bool SpectateUpdate(entity this)
1655 if(!IS_PLAYER(this.enemy) || this == this.enemy)
1657 SetSpectatee(this, NULL);
1661 SpectateCopy(this, this.enemy);
1666 bool SpectateSet(entity this)
1668 if(!IS_PLAYER(this.enemy))
1672 WriteByte(MSG_ONE, SVC_SETVIEW);
1673 WriteEntity(MSG_ONE, this.enemy);
1674 this.movetype = MOVETYPE_NONE;
1675 accuracy_resend(this);
1677 if(!SpectateUpdate(this))
1678 PutObserverInServer(this);
1683 void SetSpectatee(entity this, entity spectatee)
1685 entity old_spectatee = this.enemy;
1687 this.enemy = spectatee;
1690 // these are required to fix the spectator bug with arc
1691 if(old_spectatee && old_spectatee.arc_beam) { old_spectatee.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1692 if(this.enemy && this.enemy.arc_beam) { this.enemy.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1695 bool Spectate(entity this, entity pl)
1697 if(MUTATOR_CALLHOOK(SpectateSet, this, pl))
1699 pl = M_ARGV(1, entity);
1701 SetSpectatee(this, pl);
1702 return SpectateSet(this);
1705 bool SpectateNext(entity this)
1707 other = find(this.enemy, classname, STR_PLAYER);
1709 if (MUTATOR_CALLHOOK(SpectateNext, this, other))
1710 other = M_ARGV(1, entity);
1712 other = find(other, classname, STR_PLAYER);
1714 if(other) { SetSpectatee(this, other); }
1716 return SpectateSet(this);
1719 bool SpectatePrev(entity this)
1721 // NOTE: chain order is from the highest to the lower entnum (unlike find)
1722 other = findchain(classname, STR_PLAYER);
1723 if (!other) // no player
1726 entity first = other;
1727 // skip players until current spectated player
1729 while(other && other != this.enemy)
1730 other = other.chain;
1732 switch (MUTATOR_CALLHOOK(SpectatePrev, this, other, first))
1734 case MUT_SPECPREV_FOUND:
1735 other = M_ARGV(1, entity);
1737 case MUT_SPECPREV_RETURN:
1738 other = M_ARGV(1, entity);
1740 case MUT_SPECPREV_CONTINUE:
1744 other = other.chain;
1751 SetSpectatee(this, other);
1752 return SpectateSet(this);
1757 ShowRespawnCountdown()
1759 Update a respawn countdown display.
1762 void ShowRespawnCountdown(entity this)
1765 if(!IS_DEAD(this)) // just respawned?
1769 number = ceil(this.respawn_time - time);
1772 if(number <= this.respawn_countdown)
1774 this.respawn_countdown = number - 1;
1775 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
1776 { Send_Notification(NOTIF_ONE, this, MSG_ANNCE, Announcer_PickNumber(CNT_RESPAWN, number)); }
1781 void LeaveSpectatorMode(entity this)
1785 if(nJoinAllowed(this, this))
1787 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0)
1789 TRANSMUTE(Player, this);
1791 if(autocvar_g_campaign || autocvar_g_balance_teams)
1792 { JoinBestTeam(this, false, true); }
1794 if(autocvar_g_campaign)
1795 { campaign_bots_may_start = true; }
1797 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_PREVENT_JOIN);
1799 WITHSELF(this, PutClientInServer());
1801 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); }
1804 stuffcmd(this, "menu_showteamselect\n");
1808 // Player may not join because g_maxplayers is set
1809 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_PREVENT);
1814 * Determines whether the player is allowed to join. This depends on cvar
1815 * g_maxplayers, if it isn't used this function always return true, otherwise
1816 * it checks whether the number of currently playing players exceeds g_maxplayers.
1817 * @return int number of free slots for players, 0 if none
1819 bool nJoinAllowed(entity this, entity ignore)
1822 // this is called that way when checking if anyone may be able to join (to build qcstatus)
1823 // so report 0 free slots if restricted
1825 if(autocvar_g_forced_team_otherwise == "spectate")
1827 if(autocvar_g_forced_team_otherwise == "spectator")
1831 if(this.team_forced < 0)
1832 return false; // forced spectators can never join
1834 // TODO simplify this
1835 int totalClients = 0;
1836 int currentlyPlaying = 0;
1837 FOREACH_CLIENT(true, LAMBDA(
1840 if(IS_REAL_CLIENT(it))
1841 if(IS_PLAYER(it) || it.caplayer)
1845 if (!autocvar_g_maxplayers)
1846 return maxclients - totalClients;
1848 if(currentlyPlaying < autocvar_g_maxplayers)
1849 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
1855 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1856 * g_maxplayers_spectator_blocktime seconds
1858 void checkSpectatorBlock(entity this)
1860 if(IS_SPEC(this) || IS_OBSERVER(this))
1862 if(IS_REAL_CLIENT(this))
1864 if( time > (this.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
1865 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
1871 void PrintWelcomeMessage(entity this)
1873 if(this.motd_actived_time == 0)
1875 if (autocvar_g_campaign) {
1876 if ((IS_PLAYER(this) && PHYS_INPUT_BUTTON_INFO(this)) || (!IS_PLAYER(this))) {
1877 this.motd_actived_time = time;
1878 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, campaign_message);
1881 if (PHYS_INPUT_BUTTON_INFO(this)) {
1882 this.motd_actived_time = time;
1883 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage(this));
1887 else if(this.motd_actived_time > 0) // showing MOTD or campaign message
1889 if (autocvar_g_campaign) {
1890 if (PHYS_INPUT_BUTTON_INFO(this))
1891 this.motd_actived_time = time;
1892 else if ((time - this.motd_actived_time > 2) && IS_PLAYER(this)) { // hide it some seconds after BUTTON_INFO has been released
1893 this.motd_actived_time = 0;
1894 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1897 if (PHYS_INPUT_BUTTON_INFO(this))
1898 this.motd_actived_time = time;
1899 else if (time - this.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
1900 this.motd_actived_time = 0;
1901 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1905 else //if(this.motd_actived_time < 0) // just connected, motd is active
1907 if(PHYS_INPUT_BUTTON_INFO(this)) // BUTTON_INFO hides initial MOTD
1908 this.motd_actived_time = -2; // wait until BUTTON_INFO gets released
1909 else if(this.motd_actived_time == -2 || IS_PLAYER(this) || IS_SPEC(this))
1911 // instanctly hide MOTD
1912 this.motd_actived_time = 0;
1913 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1918 void ObserverThink(entity this)
1922 MinigameImpulse(this, this.impulse);
1925 float prefered_movetype;
1926 if (this.flags & FL_JUMPRELEASED) {
1927 if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) {
1928 this.flags &= ~FL_JUMPRELEASED;
1929 this.flags |= FL_SPAWNING;
1930 } else if(PHYS_INPUT_BUTTON_ATCK(this) && !this.version_mismatch) {
1931 this.flags &= ~FL_JUMPRELEASED;
1932 if(SpectateNext(this)) {
1933 TRANSMUTE(Spectator, this);
1936 prefered_movetype = ((!PHYS_INPUT_BUTTON_USE(this) ? this.cvar_cl_clippedspectating : !this.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
1937 if (this.movetype != prefered_movetype)
1938 this.movetype = prefered_movetype;
1941 if (!(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_JUMP(this))) {
1942 this.flags |= FL_JUMPRELEASED;
1943 if(this.flags & FL_SPAWNING)
1945 this.flags &= ~FL_SPAWNING;
1946 LeaveSpectatorMode(this);
1953 void SpectatorThink(entity this)
1957 if(MinigameImpulse(this, this.impulse))
1960 if (this.flags & FL_JUMPRELEASED) {
1961 if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) {
1962 this.flags &= ~FL_JUMPRELEASED;
1963 this.flags |= FL_SPAWNING;
1964 } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) {
1965 this.flags &= ~FL_JUMPRELEASED;
1966 if(SpectateNext(this)) {
1967 TRANSMUTE(Spectator, this);
1969 TRANSMUTE(Observer, this);
1970 WITHSELF(this, PutClientInServer());
1973 } else if(this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229)) {
1974 this.flags &= ~FL_JUMPRELEASED;
1975 if(SpectatePrev(this)) {
1976 TRANSMUTE(Spectator, this);
1978 TRANSMUTE(Observer, this);
1979 WITHSELF(this, PutClientInServer());
1982 } else if (PHYS_INPUT_BUTTON_ATCK2(this)) {
1983 this.flags &= ~FL_JUMPRELEASED;
1984 TRANSMUTE(Observer, this);
1985 WITHSELF(this, PutClientInServer());
1987 if(!SpectateUpdate(this))
1988 PutObserverInServer(this);
1991 if (!(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this))) {
1992 this.flags |= FL_JUMPRELEASED;
1993 if(this.flags & FL_SPAWNING)
1995 this.flags &= ~FL_SPAWNING;
1996 LeaveSpectatorMode(this);
2000 if(!SpectateUpdate(this))
2001 PutObserverInServer(this);
2004 this.flags |= FL_CLIENT | FL_NOTARGET;
2007 void vehicles_enter (entity pl, entity veh);
2008 void PlayerUseKey(entity this)
2010 if (!IS_PLAYER(this))
2017 vehicles_exit(this.vehicle, VHEF_NORMAL);
2021 else if(autocvar_g_vehicles_enter)
2023 if(!STAT(FROZEN, this))
2027 entity head, closest_target = world;
2028 head = WarpZone_FindRadius(this.origin, autocvar_g_vehicles_enter_radius, true);
2030 while(head) // find the closest acceptable target to enter
2032 if(head.vehicle_flags & VHF_ISVEHICLE)
2034 if(!head.owner || ((head.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(head.owner, this)))
2035 if(head.takedamage != DAMAGE_NO)
2039 if(vlen(this.origin - head.origin) < vlen(this.origin - closest_target.origin))
2040 { closest_target = head; }
2042 else { closest_target = head; }
2048 if(closest_target) { vehicles_enter(this, closest_target); return; }
2052 // a use key was pressed; call handlers
2053 MUTATOR_CALLHOOK(PlayerUseKey, this);
2061 Called every frame for each client before the physics are run
2064 .float usekeypressed;
2065 .float last_vehiclecheck;
2067 void PlayerPreThink ()
2069 SELFPARAM(); // needed for engine functions
2070 WarpZone_PlayerPhysics_FixVAngle(this);
2072 STAT(GAMESTARTTIME, this) = game_starttime;
2073 STAT(ROUNDSTARTTIME, this) = round_starttime;
2074 STAT(ALLOW_OLDVORTEXBEAM, this) = autocvar_g_allow_oldvortexbeam;
2075 STAT(LEADLIMIT, this) = autocvar_leadlimit;
2077 STAT(WEAPONSINMAP, this) = weaponsInMap;
2080 // physics frames: update anticheat stuff
2081 anticheat_prethink(this);
2084 if (blockSpectators && frametime) {
2085 // WORKAROUND: only use dropclient in server frames (frametime set).
2086 // Never use it in cl_movement frames (frametime zero).
2087 checkSpectatorBlock(this);
2090 zoomstate_set = false;
2092 // Check for nameless players
2093 if (isInvisibleString(this.netname)) {
2094 this.netname = strzone(sprintf("Player#%d", this.playerid));
2095 // stuffcmd(this, strcat("name ", this.netname, "\n")); // maybe?
2097 if (this.netname != this.netname_previous) {
2098 if (autocvar_sv_eventlog) {
2099 GameLogEcho(strcat(":name:", ftos(this.playerid), ":", this.netname));
2101 if (this.netname_previous) strunzone(this.netname_previous);
2102 this.netname_previous = strzone(this.netname);
2106 if (this.version_nagtime && this.cvar_g_xonoticversion && time > this.version_nagtime) {
2107 this.version_nagtime = 0;
2108 if (strstrofs(this.cvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(this.cvar_g_xonoticversion, "autobuild", 0) >= 0) {
2110 } else if (strstrofs(autocvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(autocvar_g_xonoticversion, "autobuild", 0) >= 0) {
2112 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2114 int r = vercmp(this.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2115 if (r < 0) { // old client
2116 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2117 } else if (r > 0) { // old server
2118 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2124 if (!(this.flags & FL_GODMODE) && this.max_armorvalue)
2126 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_GODMODE_OFF, this.max_armorvalue);
2127 this.max_armorvalue = 0;
2130 if (STAT(FROZEN, this) == 2)
2132 this.revive_progress = bound(0, this.revive_progress + frametime * this.revive_speed, 1);
2133 this.health = max(1, this.revive_progress * start_health);
2134 this.iceblock.alpha = bound(0.2, 1 - this.revive_progress, 1);
2136 if (this.revive_progress >= 1)
2139 else if (STAT(FROZEN, this) == 3)
2141 this.revive_progress = bound(0, this.revive_progress - frametime * this.revive_speed, 1);
2142 this.health = max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * this.revive_progress );
2144 if (this.health < 1)
2147 vehicles_exit(this.vehicle, VHEF_RELEASE);
2148 this.event_damage(this, this, this.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, this.origin, '0 0 0');
2150 else if (this.revive_progress <= 0)
2154 MUTATOR_CALLHOOK(PlayerPreThink, this);
2156 if(autocvar_g_vehicles_enter)
2157 if(time > this.last_vehiclecheck)
2160 if(!STAT(FROZEN, this))
2165 for(veh = world; (veh = findflags(veh, vehicle_flags, VHF_ISVEHICLE)); )
2166 if(vlen(veh.origin - this.origin) < autocvar_g_vehicles_enter_radius)
2168 if(veh.takedamage != DAMAGE_NO)
2169 if((veh.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(veh.owner, this))
2170 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
2172 if(!veh.team || SAME_TEAM(this, veh))
2173 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER);
2174 else if(autocvar_g_vehicles_steal)
2175 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
2177 this.last_vehiclecheck = time + 1;
2180 if(!this.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2182 if(PHYS_INPUT_BUTTON_USE(this) && !this.usekeypressed)
2184 this.usekeypressed = PHYS_INPUT_BUTTON_USE(this);
2187 if (IS_REAL_CLIENT(this))
2188 PrintWelcomeMessage(this);
2190 if (IS_PLAYER(this)) {
2191 CheckRules_Player(this);
2193 if (intermission_running) {
2194 IntermissionThink(this);
2198 if (timeout_status == TIMEOUT_ACTIVE) {
2199 // don't allow the player to turn around while game is paused
2200 // FIXME turn this into CSQC stuff
2201 this.v_angle = this.lastV_angle;
2202 this.angles = this.lastV_angle;
2203 this.fixangle = true;
2206 if (frametime) player_powerups(this);
2208 if (IS_DEAD(this)) {
2209 if (this.personal && g_race_qualifying) {
2210 if (time > this.respawn_time) {
2211 STAT(RESPAWN_TIME, this) = this.respawn_time = time + 1; // only retry once a second
2213 this.impulse = CHIMPULSE_SPEEDRUN.impulse;
2216 if (frametime) player_anim(this);
2217 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));
2219 if (this.deadflag == DEAD_DYING) {
2220 if ((this.respawn_flags & RESPAWN_FORCE) && !(this.respawn_time < this.respawn_time_max)) {
2221 this.deadflag = DEAD_RESPAWNING;
2222 } else if (!button_pressed) {
2223 this.deadflag = DEAD_DEAD;
2225 } else if (this.deadflag == DEAD_DEAD) {
2226 if (button_pressed) {
2227 this.deadflag = DEAD_RESPAWNABLE;
2228 } else if (time >= this.respawn_time_max && (this.respawn_flags & RESPAWN_FORCE)) {
2229 this.deadflag = DEAD_RESPAWNING;
2231 } else if (this.deadflag == DEAD_RESPAWNABLE) {
2232 if (!button_pressed) {
2233 this.deadflag = DEAD_RESPAWNING;
2235 } else if (this.deadflag == DEAD_RESPAWNING) {
2236 if (time > this.respawn_time) {
2237 this.respawn_time = time + 1; // only retry once a second
2238 this.respawn_time_max = this.respawn_time;
2243 ShowRespawnCountdown(this);
2245 if (this.respawn_flags & RESPAWN_SILENT)
2246 STAT(RESPAWN_TIME, this) = 0;
2247 else if ((this.respawn_flags & RESPAWN_FORCE) && this.respawn_time < this.respawn_time_max)
2249 if (time < this.respawn_time)
2250 STAT(RESPAWN_TIME, this) = this.respawn_time;
2251 else if (this.deadflag != DEAD_RESPAWNING)
2252 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(this);
2322 secrets_setstatus(this);
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(this);
2333 else if (IS_OBSERVER(this)) {
2334 ObserverThink(this);
2336 else if (IS_SPEC(this)) {
2337 SpectatorThink(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 ()
2418 SELFPARAM(); // needed for engine functions
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(this);
2460 UpdateChatBubble(this);
2461 if (this.impulse) ImpulseCommands(this);
2462 if (intermission_running) return; // intermission or finale
2463 GetPressedKeys(this);
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);
2471 playerdemo_write(this);
2473 CSQCMODEL_AUTOUPDATE(this);