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 MUTATOR_CALLHOOK(FixPlayermodel, defaultmodel, defaultskin);
375 defaultmodel = ret_string;
376 defaultskin = ret_int;
380 if(defaultmodel != "")
382 if (defaultmodel != player.model)
384 vector m1 = player.mins;
385 vector m2 = player.maxs;
386 setplayermodel (player, defaultmodel);
387 setsize (player, m1, m2);
391 oldskin = player.skin;
392 player.skin = defaultskin;
394 if (player.playermodel != player.model || player.playermodel == "")
396 player.playermodel = CheckPlayerModel(player.playermodel); // this is never "", so no endless loop
397 vector m1 = player.mins;
398 vector m2 = player.maxs;
399 setplayermodel (player, player.playermodel);
400 setsize (player, m1, m2);
404 oldskin = player.skin;
405 player.skin = stof(player.playerskin);
408 if(chmdl || oldskin != player.skin) // model or skin has changed
410 player.species = player_getspecies(player); // update species
411 if(!autocvar_g_debug_globalsounds)
412 UpdatePlayerSounds(player); // update skin sounds
416 if(strlen(autocvar_sv_defaultplayercolors))
417 if(player.clientcolors != stof(autocvar_sv_defaultplayercolors))
418 setcolor(player, stof(autocvar_sv_defaultplayercolors));
422 /** Called when a client spawns in the server */
423 void PutClientInServer()
426 if (IS_BOT_CLIENT(this)) {
427 TRANSMUTE(Player, this);
428 } else if (IS_REAL_CLIENT(this)) {
430 WriteByte(MSG_ONE, SVC_SETVIEW);
431 WriteEntity(MSG_ONE, this);
434 TRANSMUTE(Observer, this);
437 SetSpectatee(this, NULL);
442 MUTATOR_CALLHOOK(PutClientInServer, this);
444 if (IS_OBSERVER(this)) {
445 PutObserverInServer();
446 } else if (IS_PLAYER(this)) {
447 PlayerState_attach(this);
448 accuracy_resend(this);
451 JoinBestTeam(this, false, true);
453 entity spot = SelectSpawnPoint(false);
455 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
456 return; // spawn failed
459 TRANSMUTE(Player, this);
460 this.wasplayer = true;
461 this.iscreature = true;
462 this.teleportable = TELEPORT_NORMAL;
463 this.damagedbycontents = true;
464 this.movetype = MOVETYPE_WALK;
465 this.solid = SOLID_SLIDEBOX;
466 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
467 if (autocvar_g_playerclip_collisions)
468 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
469 if (IS_BOT_CLIENT(this) && autocvar_g_botclip_collisions)
470 this.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
471 this.frags = FRAGS_PLAYER;
472 if (INDEPENDENT_PLAYERS) MAKE_INDEPENDENT_PLAYER(this);
473 this.flags = FL_CLIENT | FL_PICKUPITEMS;
474 if (autocvar__notarget)
475 this.flags |= FL_NOTARGET;
476 this.takedamage = DAMAGE_AIM;
477 this.effects = EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
481 this.ammo_shells = warmup_start_ammo_shells;
482 this.ammo_nails = warmup_start_ammo_nails;
483 this.ammo_rockets = warmup_start_ammo_rockets;
484 this.ammo_cells = warmup_start_ammo_cells;
485 this.ammo_plasma = warmup_start_ammo_plasma;
486 this.ammo_fuel = warmup_start_ammo_fuel;
487 this.health = warmup_start_health;
488 this.armorvalue = warmup_start_armorvalue;
489 this.weapons = WARMUP_START_WEAPONS;
491 this.ammo_shells = start_ammo_shells;
492 this.ammo_nails = start_ammo_nails;
493 this.ammo_rockets = start_ammo_rockets;
494 this.ammo_cells = start_ammo_cells;
495 this.ammo_plasma = start_ammo_plasma;
496 this.ammo_fuel = start_ammo_fuel;
497 this.health = start_health;
498 this.armorvalue = start_armorvalue;
499 this.weapons = start_weapons;
502 this.superweapons_finished = (this.weapons & WEPSET_SUPERWEAPONS) ? time + autocvar_g_balance_superweapons_time : 0;
504 this.items = start_items;
506 this.spawnshieldtime = time + autocvar_g_spawnshieldtime;
507 this.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
508 this.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
509 this.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
510 this.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
511 // extend the pause of rotting if client was reset at the beginning of the countdown
512 if (!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
513 float f = game_starttime - time;
514 this.spawnshieldtime += f;
515 this.pauserotarmor_finished += f;
516 this.pauserothealth_finished += f;
517 this.pauseregen_finished += f;
519 this.damageforcescale = 2;
521 this.respawn_flags = 0;
522 this.respawn_time = 0;
523 this.stat_respawn_time = 0;
524 this.scale = autocvar_sv_player_scale;
527 this.pain_finished = 0;
529 this.think = func_null; // players have no think function
532 this.ballistics_density = autocvar_g_ballistics_density_player;
534 this.deadflag = DEAD_NO;
536 this.angles = spot.angles;
537 this.angles_z = 0; // never spawn tilted even if the spot says to
538 if (IS_BOT_CLIENT(this))
539 this.v_angle = this.angles;
540 this.fixangle = true; // turn this way immediately
541 this.oldvelocity = this.velocity = '0 0 0';
542 this.avelocity = '0 0 0';
543 this.punchangle = '0 0 0';
544 this.punchvector = '0 0 0';
546 this.strength_finished = 0;
547 this.invincible_finished = 0;
548 this.fire_endtime = -1;
549 this.revival_time = 0;
550 this.air_finished = time + 12;
552 entity spawnevent = new_pure(spawnevent);
553 spawnevent.owner = this;
554 Net_LinkEntity(spawnevent, false, 0.5, SpawnEvent_Send);
556 // Cut off any still running player sounds.
557 stopsound(this, CH_PLAYER_SINGLE);
560 FixPlayermodel(this);
561 this.drawonlytoclient = NULL;
564 this.view_ofs = STAT(PL_VIEW_OFS, NULL);
565 setsize(this, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
566 this.spawnorigin = spot.origin;
567 setorigin(this, spot.origin + '0 0 1' * (1 - this.mins.z - 24));
568 // don't reset back to last position, even if new position is stuck in solid
569 this.oldorigin = this.origin;
570 this.prevorigin = this.origin;
571 this.lastteleporttime = time; // prevent insane speeds due to changing origin
572 this.hud = HUD_NORMAL;
574 this.event_damage = PlayerDamage;
576 this.bot_attack = true;
577 this.monster_attack = true;
579 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_JUMP(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
581 if (this.killcount == FRAGS_SPECTATOR) {
582 PlayerScore_Clear(this);
586 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
588 CL_SpawnWeaponentity(this, weaponentities[slot]);
590 this.alpha = default_player_alpha;
591 this.colormod = '1 1 1' * autocvar_g_player_brightness;
592 this.exteriorweaponentity.alpha = default_weapon_alpha;
594 this.speedrunning = false;
596 target_voicescript_clear(this);
598 // reset fields the weapons may use
599 FOREACH(Weapons, true, LAMBDA(
600 it.wr_resetplayer(it);
601 // reload all reloadable weapons
602 if (it.spawnflags & WEP_FLAG_RELOADABLE) {
603 this.weapon_load[it.m_id] = it.reloading_ammo;
608 string s = spot.target;
609 spot.target = string_null;
610 SUB_UseTargets(spot, this, NULL);
616 MUTATOR_CALLHOOK(PlayerSpawn, spot);
618 if (autocvar_spawn_debug)
620 sprint(this, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
621 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
624 PS(this).m_switchweapon = w_getbestweapon(this);
625 this.cnt = -1; // W_LastWeapon will not complain
626 PS(this).m_weapon = WEP_Null;
627 this.weaponname = "";
628 PS(this).m_switchingweapon = WEP_Null;
630 if (!warmup_stage && !this.alivetime)
631 this.alivetime = time;
633 antilag_clear(this, CS(this));
637 void ClientInit_misc();
639 .float ebouncefactor, ebouncestop; // electro's values
640 // TODO do we need all these fields, or should we stop autodetecting runtime
641 // changes and just have a console command to update this?
642 bool ClientInit_SendEntity(entity this, entity to, int sf)
644 WriteHeader(MSG_ENTITY, _ENT_CLIENT_INIT);
647 // MSG_INIT replacement
648 // TODO: make easier to use
650 W_PROP_reload(MSG_ONE, to);
652 MUTATOR_CALLHOOK(Ent_Init);
654 void ClientInit_misc()
657 int channel = MSG_ONE;
658 WriteHeader(channel, ENT_CLIENT_INIT);
659 WriteByte(channel, g_nexball_meter_period * 32);
660 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[0]));
661 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[1]));
662 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[2]));
663 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[3]));
664 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[0]));
665 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[1]));
666 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[2]));
667 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[3]));
669 if(sv_foginterval && world.fog != "")
670 WriteString(channel, world.fog);
672 WriteString(channel, "");
673 WriteByte(channel, this.count * 255.0); // g_balance_armor_blockpercent
674 WriteByte(channel, serverflags); // client has to know if it should zoom or not
675 WriteCoord(channel, autocvar_g_trueaim_minrange);
678 void ClientInit_CheckUpdate()
680 this.nextthink = time;
681 if(this.count != autocvar_g_balance_armor_blockpercent)
683 this.count = autocvar_g_balance_armor_blockpercent;
688 void ClientInit_Spawn()
691 entity e = new_pure(clientinit);
692 e.think = ClientInit_CheckUpdate;
693 Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
695 WITHSELF(e, ClientInit_CheckUpdate());
705 // initialize parms for a new player
706 parm1 = -(86400 * 366);
708 MUTATOR_CALLHOOK(SetNewParms);
716 void SetChangeParms ()
718 // save parms for level change
719 parm1 = this.parm_idlesince - time;
721 MUTATOR_CALLHOOK(SetChangeParms);
729 void DecodeLevelParms(entity this)
732 this.parm_idlesince = parm1;
733 if (this.parm_idlesince == -(86400 * 366))
734 this.parm_idlesince = time;
736 // whatever happens, allow 60 seconds of idling directly after connect for map loading
737 this.parm_idlesince = max(this.parm_idlesince, time - sv_maxidle + 60);
739 MUTATOR_CALLHOOK(DecodeLevelParms);
746 Called when a client types 'kill' in the console
750 .float clientkill_nexttime;
751 void ClientKill_Now_TeamChange(entity this)
753 if(this.killindicator_teamchange == -1)
755 JoinBestTeam( this, false, true );
757 else if(this.killindicator_teamchange == -2)
760 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
761 WITHSELF(this, PutObserverInServer());
764 WITHSELF(this, SV_ChangeTeam(this.killindicator_teamchange - 1));
765 this.killindicator_teamchange = 0;
768 void ClientKill_Now()
772 vehicles_exit(VHEF_RELEASE);
773 if(!this.killindicator_teamchange)
775 this.vehicle_health = -1;
776 Damage(this, this, this, 1 , DEATH_KILL.m_id, this.origin, '0 0 0');
780 if(this.killindicator && !wasfreed(this.killindicator))
781 remove(this.killindicator);
783 this.killindicator = world;
785 if(this.killindicator_teamchange)
786 ClientKill_Now_TeamChange(this);
789 Damage(this, this, this, 100000, DEATH_KILL.m_id, this.origin, '0 0 0');
791 // now I am sure the player IS dead
793 void KillIndicator_Think()
797 this.owner.killindicator = world;
802 if (this.owner.alpha < 0 && !this.owner.vehicle)
804 this.owner.killindicator = world;
811 WITHSELF(this.owner, ClientKill_Now());
814 else if(g_cts && this.health == 1) // health == 1 means that it's silent
816 this.nextthink = time + 1;
822 setmodel(this, MDL_NUM(this.cnt));
823 if(IS_REAL_CLIENT(this.owner))
826 { Send_Notification(NOTIF_ONE, this.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, this.cnt)); }
828 this.nextthink = time + 1;
833 float clientkilltime;
834 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
843 killtime = autocvar_g_balance_kill_delay;
845 if(g_race_qualifying || g_cts)
848 if(MUTATOR_CALLHOOK(ClientKill, this, killtime))
851 this.killindicator_teamchange = targetteam;
853 if(!this.killindicator)
857 killtime = max(killtime, this.clientkill_nexttime - time);
858 this.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
861 if(killtime <= 0 || !IS_PLAYER(this) || IS_DEAD(this))
867 starttime = max(time, clientkilltime);
869 this.killindicator = spawn();
870 this.killindicator.owner = this;
871 this.killindicator.scale = 0.5;
872 setattachment(this.killindicator, this, "");
873 setorigin(this.killindicator, '0 0 52');
874 this.killindicator.think = KillIndicator_Think;
875 this.killindicator.nextthink = starttime + (this.lip) * 0.05;
876 clientkilltime = max(clientkilltime, this.killindicator.nextthink + 0.05);
877 this.killindicator.cnt = ceil(killtime);
878 this.killindicator.count = bound(0, ceil(killtime), 10);
879 //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
881 for(e = world; (e = find(e, classname, "body")) != world; )
885 e.killindicator = spawn();
886 e.killindicator.owner = e;
887 e.killindicator.scale = 0.5;
888 setattachment(e.killindicator, e, "");
889 setorigin(e.killindicator, '0 0 52');
890 e.killindicator.think = KillIndicator_Think;
891 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
892 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
893 e.killindicator.cnt = ceil(killtime);
898 if(this.killindicator)
900 if(targetteam == 0) // just die
902 this.killindicator.colormod = '0 0 0';
903 if(IS_REAL_CLIENT(this))
904 if(this.killindicator.cnt > 0)
905 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, this.killindicator.cnt);
907 else if(targetteam == -1) // auto
909 this.killindicator.colormod = '0 1 0';
910 if(IS_REAL_CLIENT(this))
911 if(this.killindicator.cnt > 0)
912 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, this.killindicator.cnt);
914 else if(targetteam == -2) // spectate
916 this.killindicator.colormod = '0.5 0.5 0.5';
917 if(IS_REAL_CLIENT(this))
918 if(this.killindicator.cnt > 0)
919 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, this.killindicator.cnt);
923 this.killindicator.colormod = Team_ColorRGB(targetteam);
924 if(IS_REAL_CLIENT(this))
925 if(this.killindicator.cnt > 0)
926 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE), this.killindicator.cnt);
935 if(this.player_blocked) return;
936 if(STAT(FROZEN, this)) return;
938 ClientKill_TeamChange(0);
941 void FixClientCvars(entity e)
943 // send prediction settings to the client
944 stuffcmd(e, "\nin_bindmap 0 0\n");
945 if(autocvar_g_antilag == 3) // client side hitscan
946 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
947 if(autocvar_sv_gentle)
948 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
950 MUTATOR_CALLHOOK(FixClientCvars, e);
953 float PlayerInIDList(entity p, string idlist)
958 // NOTE: we do NOT check crypto_idfp_signed here, an unsigned ID is fine too for this
962 // this function allows abbreviated player IDs too!
963 n = tokenize_console(idlist);
964 for(i = 0; i < n; ++i)
967 if(s == substring(p.crypto_idfp, 0, strlen(s)))
974 #ifdef DP_EXT_PRECONNECT
979 Called once (not at each match start) when a client begins a connection to the server
982 void ClientPreConnect ()
984 if(autocvar_sv_eventlog)
986 GameLogEcho(sprintf(":connect:%d:%d:%s",
989 ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot")
999 Called when a client connects to the server
1002 void ClientConnect()
1005 if (Ban_MaybeEnforceBanOnce(this)) return;
1006 assert(!IS_CLIENT(this), return);
1007 this.flags |= FL_CLIENT;
1008 assert(player_count >= 0, player_count = 0);
1011 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_WATERMARK, WATERMARK);
1013 this.version_nagtime = time + 10 + random() * 10;
1014 TRANSMUTE(Client, this);
1016 // identify the right forced team
1017 if (autocvar_g_campaign)
1019 if (IS_REAL_CLIENT(this)) // only players, not bots
1021 switch (autocvar_g_campaign_forceteam)
1023 case 1: this.team_forced = NUM_TEAM_1; break;
1024 case 2: this.team_forced = NUM_TEAM_2; break;
1025 case 3: this.team_forced = NUM_TEAM_3; break;
1026 case 4: this.team_forced = NUM_TEAM_4; break;
1027 default: this.team_forced = 0;
1031 else if (PlayerInIDList(this, autocvar_g_forced_team_red)) this.team_forced = NUM_TEAM_1;
1032 else if (PlayerInIDList(this, autocvar_g_forced_team_blue)) this.team_forced = NUM_TEAM_2;
1033 else if (PlayerInIDList(this, autocvar_g_forced_team_yellow)) this.team_forced = NUM_TEAM_3;
1034 else if (PlayerInIDList(this, autocvar_g_forced_team_pink)) this.team_forced = NUM_TEAM_4;
1035 else switch (autocvar_g_forced_team_otherwise)
1037 default: this.team_forced = 0; break;
1038 case "red": this.team_forced = NUM_TEAM_1; break;
1039 case "blue": this.team_forced = NUM_TEAM_2; break;
1040 case "yellow": this.team_forced = NUM_TEAM_3; break;
1041 case "pink": this.team_forced = NUM_TEAM_4; break;
1044 this.team_forced = -1;
1047 if (!teamplay && this.team_forced > 0) this.team_forced = 0;
1050 int id = this.playerid;
1051 this.playerid = 0; // silent
1052 JoinBestTeam(this, false, false); // if the team number is valid, keep it
1056 if (autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) {
1057 TRANSMUTE(Observer, this);
1059 if (!teamplay || autocvar_g_balance_teams) {
1060 TRANSMUTE(Player, this);
1061 campaign_bots_may_start = true;
1063 TRANSMUTE(Observer, this); // do it anyway
1067 PlayerStats_GameReport_AddEvent(sprintf("kills-%d", this.playerid));
1069 // always track bots, don't ask for cl_allow_uidtracking
1070 if (IS_BOT_CLIENT(this)) PlayerStats_GameReport_AddPlayer(this);
1072 if (autocvar_sv_eventlog)
1073 GameLogEcho(strcat(":join:", ftos(this.playerid), ":", ftos(etof(this)), ":", ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot"), ":", this.netname));
1075 LogTeamchange(this.playerid, this.team, 1);
1077 this.just_joined = true; // stop spamming the eventlog with additional lines when the client connects
1079 this.netname_previous = strzone(this.netname);
1081 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && IS_PLAYER(this)) ? APP_TEAM_ENT(this, INFO_JOIN_CONNECT_TEAM) : INFO_JOIN_CONNECT), this.netname);
1083 stuffcmd(this, clientstuff, "\n");
1084 stuffcmd(this, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1086 FixClientCvars(this);
1088 // get version info from player
1089 stuffcmd(this, "cmd clientversion $gameversion\n");
1091 // notify about available teams
1094 CheckAllowedTeams(this);
1096 if (c1 >= 0) t |= BIT(0);
1097 if (c2 >= 0) t |= BIT(1);
1098 if (c3 >= 0) t |= BIT(2);
1099 if (c4 >= 0) t |= BIT(3);
1100 stuffcmd(this, sprintf("set _teams_available %d\n", t));
1104 stuffcmd(this, "set _teams_available 0\n");
1107 bot_relinkplayerlist();
1109 this.spectatortime = time;
1110 if (blockSpectators)
1112 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1115 this.jointime = time;
1116 this.allowed_timeouts = autocvar_sv_timeout_number;
1118 if (IS_REAL_CLIENT(this))
1120 if (!autocvar_g_campaign)
1122 this.motd_actived_time = -1;
1123 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1126 if (g_weaponarena_weapons == WEPSET(TUBA))
1127 stuffcmd(this, "cl_cmd settemp chase_active 1\n");
1130 if (!sv_foginterval && world.fog != "")
1131 stuffcmd(this, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1133 if (autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)))
1134 if (!g_ca && !g_cts && !g_race) // teamnagger is currently bad for ca, race & cts
1135 send_CSQC_teamnagger();
1137 CSQCMODEL_AUTOINIT(this);
1139 this.model_randomizer = random();
1141 if (IS_REAL_CLIENT(this))
1142 sv_notice_join(this);
1144 FOREACH_ENTITY_FLOAT(init_for_player_needed, true, {
1145 WITHSELF(it, it.init_for_player(it));
1148 MUTATOR_CALLHOOK(ClientConnect, this);
1154 Called when a client disconnects from the server
1157 .entity chatbubbleentity;
1159 void ClientDisconnect()
1162 assert(IS_CLIENT(this), return);
1164 PlayerStats_GameReport_FinalizePlayer(this);
1165 if (this.vehicle) vehicles_exit(VHEF_RELEASE);
1166 if (this.active_minigame) part_minigame(this);
1167 if (IS_PLAYER(this)) Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
1169 if (autocvar_sv_eventlog)
1170 GameLogEcho(strcat(":part:", ftos(this.playerid)));
1172 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
1174 MUTATOR_CALLHOOK(ClientDisconnect);
1176 ClientState_detach(this);
1178 Portal_ClearAll(this);
1182 RemoveGrapplingHook(this);
1184 // Here, everything has been done that requires this player to be a client.
1186 this.flags &= ~FL_CLIENT;
1188 if (this.chatbubbleentity) remove(this.chatbubbleentity);
1189 if (this.killindicator) remove(this.killindicator);
1191 WaypointSprite_PlayerGone();
1193 bot_relinkplayerlist();
1195 if (this.netname_previous) strunzone(this.netname_previous);
1196 if (this.clientstatus) strunzone(this.clientstatus);
1197 if (this.weaponorder_byimpulse) strunzone(this.weaponorder_byimpulse);
1198 if (this.personal) remove(this.personal);
1202 if (vote_called && IS_REAL_CLIENT(this)) VoteCount(false);
1205 void ChatBubbleThink()
1207 this.nextthink = time;
1208 if ((this.owner.alpha < 0) || this.owner.chatbubbleentity != this)
1210 if(this.owner) // but why can that ever be world?
1211 this.owner.chatbubbleentity = world;
1218 if ( !IS_DEAD(this.owner) && IS_PLAYER(this.owner) )
1220 if ( this.owner.active_minigame )
1221 this.mdl = "models/sprites/minigame_busy.iqm";
1222 else if (PHYS_INPUT_BUTTON_CHAT(this.owner))
1223 this.mdl = "models/misc/chatbubble.spr";
1226 if ( this.model != this.mdl )
1227 _setmodel(this, this.mdl);
1231 void UpdateChatBubble()
1235 // spawn a chatbubble entity if needed
1236 if (!this.chatbubbleentity)
1238 this.chatbubbleentity = new(chatbubbleentity);
1239 this.chatbubbleentity.owner = this;
1240 this.chatbubbleentity.exteriormodeltoclient = this;
1241 this.chatbubbleentity.think = ChatBubbleThink;
1242 this.chatbubbleentity.nextthink = time;
1243 setmodel(this.chatbubbleentity, MDL_CHAT); // precision set below
1244 //setorigin(this.chatbubbleentity, this.origin + '0 0 15' + this.maxs_z * '0 0 1');
1245 setorigin(this.chatbubbleentity, '0 0 15' + this.maxs_z * '0 0 1');
1246 setattachment(this.chatbubbleentity, this, ""); // sticks to moving player better, also conserves bandwidth
1247 this.chatbubbleentity.mdl = this.chatbubbleentity.model;
1248 //this.chatbubbleentity.model = "";
1249 this.chatbubbleentity.effects = EF_LOWPRECISION;
1254 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1255 // added to the model skins
1256 /*void UpdateColorModHack()
1259 c = this.clientcolors & 15;
1260 // LordHavoc: only bothering to support white, green, red, yellow, blue
1261 if (!teamplay) this.colormod = '0 0 0';
1262 else if (c == 0) this.colormod = '1.00 1.00 1.00';
1263 else if (c == 3) this.colormod = '0.10 1.73 0.10';
1264 else if (c == 4) this.colormod = '1.73 0.10 0.10';
1265 else if (c == 12) this.colormod = '1.22 1.22 0.10';
1266 else if (c == 13) this.colormod = '0.10 0.10 1.73';
1267 else this.colormod = '1 1 1';
1272 if(this.alpha >= 0 && autocvar_g_respawn_ghosts)
1274 this.solid = SOLID_NOT;
1275 this.takedamage = DAMAGE_NO;
1276 this.movetype = MOVETYPE_FLY;
1277 this.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1278 this.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1279 this.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1280 Send_Effect(EFFECT_RESPAWN_GHOST, this.origin, '0 0 0', 1);
1281 if(autocvar_g_respawn_ghosts_maxtime)
1282 SUB_SetFade (this, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1287 this.effects |= EF_NODRAW; // prevent another CopyBody
1288 PutClientInServer();
1291 void play_countdown(float finished, Sound samp)
1294 if(IS_REAL_CLIENT(this))
1295 if(floor(finished - time - frametime) != floor(finished - time))
1296 if(finished - time < 6)
1297 sound (this, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
1300 void player_powerups ()
1302 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1303 int items_prev = this.items;
1305 if((this.items & IT_USING_JETPACK) && !IS_DEAD(this) && !gameover)
1306 this.modelflags |= MF_ROCKET;
1308 this.modelflags &= ~MF_ROCKET;
1310 this.effects &= ~(EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1312 if((this.alpha < 0 || IS_DEAD(this)) && !this.vehicle) // don't apply the flags if the player is gibbed
1315 Fire_ApplyDamage(this);
1316 Fire_ApplyEffect(this);
1320 if (this.items & ITEM_Strength.m_itemid)
1322 play_countdown(this.strength_finished, SND_POWEROFF);
1323 this.effects = this.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1324 if (time > this.strength_finished)
1326 this.items = this.items - (this.items & ITEM_Strength.m_itemid);
1327 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, this.netname);
1328 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
1333 if (time < this.strength_finished)
1335 this.items = this.items | ITEM_Strength.m_itemid;
1336 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, this.netname);
1337 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERUP_STRENGTH);
1340 if (this.items & ITEM_Shield.m_itemid)
1342 play_countdown(this.invincible_finished, SND_POWEROFF);
1343 this.effects = this.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1344 if (time > this.invincible_finished)
1346 this.items = this.items - (this.items & ITEM_Shield.m_itemid);
1347 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, this.netname);
1348 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
1353 if (time < this.invincible_finished)
1355 this.items = this.items | ITEM_Shield.m_itemid;
1356 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, this.netname);
1357 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERUP_SHIELD);
1360 if (this.items & IT_SUPERWEAPON)
1362 if (!(this.weapons & WEPSET_SUPERWEAPONS))
1364 this.superweapons_finished = 0;
1365 this.items = this.items - (this.items & IT_SUPERWEAPON);
1366 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, this.netname);
1367 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1369 else if (this.items & IT_UNLIMITED_SUPERWEAPONS)
1371 // don't let them run out
1375 play_countdown(this.superweapons_finished, SND_POWEROFF);
1376 if (time > this.superweapons_finished)
1378 this.items = this.items - (this.items & IT_SUPERWEAPON);
1379 this.weapons &= ~WEPSET_SUPERWEAPONS;
1380 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, this.netname);
1381 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1385 else if(this.weapons & WEPSET_SUPERWEAPONS)
1387 if (time < this.superweapons_finished || (this.items & IT_UNLIMITED_SUPERWEAPONS))
1389 this.items = this.items | IT_SUPERWEAPON;
1390 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, this.netname);
1391 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1395 this.superweapons_finished = 0;
1396 this.weapons &= ~WEPSET_SUPERWEAPONS;
1401 this.superweapons_finished = 0;
1405 if(autocvar_g_nodepthtestplayers)
1406 this.effects = this.effects | EF_NODEPTHTEST;
1408 if(autocvar_g_fullbrightplayers)
1409 this.effects = this.effects | EF_FULLBRIGHT;
1411 if (time >= game_starttime)
1412 if (time < this.spawnshieldtime)
1413 this.effects = this.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1415 MUTATOR_CALLHOOK(PlayerPowerups, this, items_prev);
1418 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1420 if(current > stable)
1422 else if(current > stable - 0.25) // when close enough, "snap"
1425 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1428 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1430 if(current < stable)
1432 else if(current < stable + 0.25) // when close enough, "snap"
1435 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1438 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1440 if(current > rotstable)
1442 if(rotframetime > 0)
1444 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1445 current = max(rotstable, current - rotlinear * rotframetime);
1448 else if(current < regenstable)
1450 if(regenframetime > 0)
1452 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1453 current = min(regenstable, current + regenlinear * regenframetime);
1463 void player_regen ()
1465 float max_mod, regen_mod, rot_mod, limit_mod;
1466 max_mod = regen_mod = rot_mod = limit_mod = 1;
1467 regen_mod_max = max_mod;
1468 regen_mod_regen = regen_mod;
1469 regen_mod_rot = rot_mod;
1470 regen_mod_limit = limit_mod;
1472 regen_health = autocvar_g_balance_health_regen;
1473 regen_health_linear = autocvar_g_balance_health_regenlinear;
1474 regen_health_rot = autocvar_g_balance_health_rot;
1475 regen_health_rotlinear = autocvar_g_balance_health_rotlinear;
1476 regen_health_stable = autocvar_g_balance_health_regenstable;
1477 regen_health_rotstable = autocvar_g_balance_health_rotstable;
1478 if(!MUTATOR_CALLHOOK(PlayerRegen))
1479 if(!STAT(FROZEN, this))
1481 float mina, maxa, limith, limita;
1482 maxa = autocvar_g_balance_armor_rotstable;
1483 mina = autocvar_g_balance_armor_regenstable;
1484 limith = autocvar_g_balance_health_limit;
1485 limita = autocvar_g_balance_armor_limit;
1487 max_mod = regen_mod_max;
1488 regen_mod = regen_mod_regen;
1489 rot_mod = regen_mod_rot;
1490 limit_mod = regen_mod_limit;
1492 regen_health_rotstable = regen_health_rotstable * max_mod;
1493 regen_health_stable = regen_health_stable * max_mod;
1494 limith = limith * limit_mod;
1495 limita = limita * limit_mod;
1497 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);
1498 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);
1501 // if player rotted to death... die!
1502 // check this outside above checks, as player may still be able to rot to death
1506 vehicles_exit(VHEF_RELEASE);
1507 if(this.event_damage)
1508 this.event_damage(this, this, this, 1, DEATH_ROT.m_id, this.origin, '0 0 0');
1511 if (!(this.items & IT_UNLIMITED_WEAPON_AMMO))
1513 float minf, maxf, limitf;
1515 maxf = autocvar_g_balance_fuel_rotstable;
1516 minf = autocvar_g_balance_fuel_regenstable;
1517 limitf = autocvar_g_balance_fuel_limit;
1519 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);
1524 void SetZoomState(float z)
1526 if(z != this.zoomstate)
1529 ClientData_Touch(this);
1531 zoomstate_set = true;
1534 void GetPressedKeys()
1537 MUTATOR_CALLHOOK(GetPressedKeys);
1538 int keys = this.pressedkeys;
1539 keys = BITSET(keys, KEY_FORWARD, this.movement.x > 0);
1540 keys = BITSET(keys, KEY_BACKWARD, this.movement.x < 0);
1541 keys = BITSET(keys, KEY_RIGHT, this.movement.y > 0);
1542 keys = BITSET(keys, KEY_LEFT, this.movement.y < 0);
1544 keys = BITSET(keys, KEY_JUMP, PHYS_INPUT_BUTTON_JUMP(this));
1545 keys = BITSET(keys, KEY_CROUCH, PHYS_INPUT_BUTTON_CROUCH(this));
1546 keys = BITSET(keys, KEY_ATCK, PHYS_INPUT_BUTTON_ATCK(this));
1547 keys = BITSET(keys, KEY_ATCK2, PHYS_INPUT_BUTTON_ATCK2(this));
1548 this.pressedkeys = keys;
1552 ======================
1553 spectate mode routines
1554 ======================
1557 void SpectateCopy(entity this, entity spectatee)
1559 TC(Client, this); TC(Client, spectatee);
1561 MUTATOR_CALLHOOK(SpectateCopy, spectatee, this);
1562 PS(this) = PS(spectatee);
1563 this.armortype = spectatee.armortype;
1564 this.armorvalue = spectatee.armorvalue;
1565 this.ammo_cells = spectatee.ammo_cells;
1566 this.ammo_plasma = spectatee.ammo_plasma;
1567 this.ammo_shells = spectatee.ammo_shells;
1568 this.ammo_nails = spectatee.ammo_nails;
1569 this.ammo_rockets = spectatee.ammo_rockets;
1570 this.ammo_fuel = spectatee.ammo_fuel;
1571 this.clip_load = spectatee.clip_load;
1572 this.clip_size = spectatee.clip_size;
1573 this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1574 this.health = spectatee.health;
1576 this.items = spectatee.items;
1577 this.last_pickup = spectatee.last_pickup;
1578 this.hit_time = spectatee.hit_time;
1579 this.strength_finished = spectatee.strength_finished;
1580 this.invincible_finished = spectatee.invincible_finished;
1581 this.pressedkeys = spectatee.pressedkeys;
1582 this.weapons = spectatee.weapons;
1583 this.vortex_charge = spectatee.vortex_charge;
1584 this.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
1585 this.hagar_load = spectatee.hagar_load;
1586 this.arc_heat_percent = spectatee.arc_heat_percent;
1587 this.minelayer_mines = spectatee.minelayer_mines;
1588 this.punchangle = spectatee.punchangle;
1589 this.view_ofs = spectatee.view_ofs;
1590 this.velocity = spectatee.velocity;
1591 this.dmg_take = spectatee.dmg_take;
1592 this.dmg_save = spectatee.dmg_save;
1593 this.dmg_inflictor = spectatee.dmg_inflictor;
1594 this.v_angle = spectatee.v_angle;
1595 this.angles = spectatee.v_angle;
1596 STAT(FROZEN, this) = STAT(FROZEN, spectatee);
1597 this.revive_progress = spectatee.revive_progress;
1598 if(!PHYS_INPUT_BUTTON_USE(this))
1599 this.fixangle = true;
1600 setorigin(this, spectatee.origin);
1601 setsize(this, spectatee.mins, spectatee.maxs);
1602 SetZoomState(spectatee.zoomstate);
1604 anticheat_spectatecopy(this, spectatee);
1605 this.hud = spectatee.hud;
1606 if(spectatee.vehicle)
1608 this.fixangle = false;
1609 //this.velocity = spectatee.vehicle.velocity;
1610 this.vehicle_health = spectatee.vehicle_health;
1611 this.vehicle_shield = spectatee.vehicle_shield;
1612 this.vehicle_energy = spectatee.vehicle_energy;
1613 this.vehicle_ammo1 = spectatee.vehicle_ammo1;
1614 this.vehicle_ammo2 = spectatee.vehicle_ammo2;
1615 this.vehicle_reload1 = spectatee.vehicle_reload1;
1616 this.vehicle_reload2 = spectatee.vehicle_reload2;
1620 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1621 WriteAngle(MSG_ONE, spectatee.v_angle.x);
1622 WriteAngle(MSG_ONE, spectatee.v_angle.y);
1623 WriteAngle(MSG_ONE, spectatee.v_angle.z);
1625 //WriteByte (MSG_ONE, SVC_SETVIEW);
1626 // WriteEntity(MSG_ONE, this);
1627 //makevectors(spectatee.v_angle);
1628 //setorigin(this, spectatee.origin - v_forward * 400 + v_up * 300);*/
1632 bool SpectateUpdate()
1637 if(!IS_PLAYER(this.enemy) || this == this.enemy)
1639 SetSpectatee(this, NULL);
1643 SpectateCopy(this, this.enemy);
1650 if(!IS_PLAYER(this.enemy))
1654 WriteByte(MSG_ONE, SVC_SETVIEW);
1655 WriteEntity(MSG_ONE, this.enemy);
1656 this.movetype = MOVETYPE_NONE;
1657 accuracy_resend(this);
1659 if(!SpectateUpdate())
1660 PutObserverInServer();
1665 void SetSpectatee(entity player, entity spectatee)
1667 entity old_spectatee = player.enemy;
1669 player.enemy = spectatee;
1672 // these are required to fix the spectator bug with arc
1673 if(old_spectatee && old_spectatee.arc_beam) { old_spectatee.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1674 if(player.enemy && player.enemy.arc_beam) { player.enemy.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1677 bool Spectate(entity pl)
1679 if(MUTATOR_CALLHOOK(SpectateSet, this, pl))
1683 SetSpectatee(this, pl);
1684 return SpectateSet();
1689 other = find(this.enemy, classname, STR_PLAYER);
1691 if (MUTATOR_CALLHOOK(SpectateNext, this, other))
1692 other = spec_player;
1694 other = find(other, classname, STR_PLAYER);
1696 if(other) { SetSpectatee(this, other); }
1698 return SpectateSet();
1703 // NOTE: chain order is from the highest to the lower entnum (unlike find)
1704 other = findchain(classname, STR_PLAYER);
1705 if (!other) // no player
1708 entity first = other;
1709 // skip players until current spectated player
1711 while(other && other != this.enemy)
1712 other = other.chain;
1714 switch (MUTATOR_CALLHOOK(SpectatePrev, this, other, first))
1716 case MUT_SPECPREV_FOUND:
1717 other = spec_player;
1719 case MUT_SPECPREV_RETURN:
1720 other = spec_player;
1722 case MUT_SPECPREV_CONTINUE:
1726 other = other.chain;
1733 SetSpectatee(this, other);
1734 return SpectateSet();
1739 ShowRespawnCountdown()
1741 Update a respawn countdown display.
1744 void ShowRespawnCountdown()
1747 if(!IS_DEAD(this)) // just respawned?
1751 number = ceil(this.respawn_time - time);
1754 if(number <= this.respawn_countdown)
1756 this.respawn_countdown = number - 1;
1757 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
1758 { Send_Notification(NOTIF_ONE, this, MSG_ANNCE, Announcer_PickNumber(CNT_RESPAWN, number)); }
1763 void LeaveSpectatorMode()
1767 if(nJoinAllowed(this, this))
1769 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0)
1771 TRANSMUTE(Player, this);
1773 if(autocvar_g_campaign || autocvar_g_balance_teams)
1774 { JoinBestTeam(this, false, true); }
1776 if(autocvar_g_campaign)
1777 { campaign_bots_may_start = true; }
1779 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_PREVENT_JOIN);
1781 PutClientInServer();
1783 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); }
1786 stuffcmd(this, "menu_showteamselect\n");
1790 // Player may not join because g_maxplayers is set
1791 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_PREVENT);
1796 * Determines whether the player is allowed to join. This depends on cvar
1797 * g_maxplayers, if it isn't used this function always return true, otherwise
1798 * it checks whether the number of currently playing players exceeds g_maxplayers.
1799 * @return int number of free slots for players, 0 if none
1801 bool nJoinAllowed(entity this, entity ignore)
1804 // this is called that way when checking if anyone may be able to join (to build qcstatus)
1805 // so report 0 free slots if restricted
1807 if(autocvar_g_forced_team_otherwise == "spectate")
1809 if(autocvar_g_forced_team_otherwise == "spectator")
1813 if(this.team_forced < 0)
1814 return false; // forced spectators can never join
1816 // TODO simplify this
1817 int totalClients = 0;
1818 int currentlyPlaying = 0;
1819 FOREACH_CLIENT(true, LAMBDA(
1822 if(IS_REAL_CLIENT(it))
1823 if(IS_PLAYER(it) || it.caplayer)
1827 if (!autocvar_g_maxplayers)
1828 return maxclients - totalClients;
1830 if(currentlyPlaying < autocvar_g_maxplayers)
1831 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
1837 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1838 * g_maxplayers_spectator_blocktime seconds
1840 void checkSpectatorBlock()
1842 if(IS_SPEC(this) || IS_OBSERVER(this))
1844 if(IS_REAL_CLIENT(this))
1846 if( time > (this.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
1847 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
1853 void PrintWelcomeMessage(entity this)
1855 if(this.motd_actived_time == 0)
1857 if (autocvar_g_campaign) {
1858 if ((IS_PLAYER(this) && PHYS_INPUT_BUTTON_INFO(this)) || (!IS_PLAYER(this))) {
1859 this.motd_actived_time = time;
1860 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, campaign_message);
1863 if (PHYS_INPUT_BUTTON_INFO(this)) {
1864 this.motd_actived_time = time;
1865 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1869 else if(this.motd_actived_time > 0) // showing MOTD or campaign message
1871 if (autocvar_g_campaign) {
1872 if (PHYS_INPUT_BUTTON_INFO(this))
1873 this.motd_actived_time = time;
1874 else if ((time - this.motd_actived_time > 2) && IS_PLAYER(this)) { // hide it some seconds after BUTTON_INFO has been released
1875 this.motd_actived_time = 0;
1876 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1879 if (PHYS_INPUT_BUTTON_INFO(this))
1880 this.motd_actived_time = time;
1881 else if (time - this.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
1882 this.motd_actived_time = 0;
1883 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1887 else //if(this.motd_actived_time < 0) // just connected, motd is active
1889 if(PHYS_INPUT_BUTTON_INFO(this)) // BUTTON_INFO hides initial MOTD
1890 this.motd_actived_time = -2; // wait until BUTTON_INFO gets released
1891 else if(this.motd_actived_time == -2 || IS_PLAYER(this) || IS_SPEC(this))
1893 // instanctly hide MOTD
1894 this.motd_actived_time = 0;
1895 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
1900 void ObserverThink()
1904 MinigameImpulse(this, this.impulse);
1907 float prefered_movetype;
1908 if (this.flags & FL_JUMPRELEASED) {
1909 if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) {
1910 this.flags &= ~FL_JUMPRELEASED;
1911 this.flags |= FL_SPAWNING;
1912 } else if(PHYS_INPUT_BUTTON_ATCK(this) && !this.version_mismatch) {
1913 this.flags &= ~FL_JUMPRELEASED;
1914 if(SpectateNext()) {
1915 TRANSMUTE(Spectator, this);
1918 prefered_movetype = ((!PHYS_INPUT_BUTTON_USE(this) ? this.cvar_cl_clippedspectating : !this.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
1919 if (this.movetype != prefered_movetype)
1920 this.movetype = prefered_movetype;
1923 if (!(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_JUMP(this))) {
1924 this.flags |= FL_JUMPRELEASED;
1925 if(this.flags & FL_SPAWNING)
1927 this.flags &= ~FL_SPAWNING;
1928 LeaveSpectatorMode();
1935 void SpectatorThink()
1939 if(MinigameImpulse(this, this.impulse))
1942 if (this.flags & FL_JUMPRELEASED) {
1943 if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) {
1944 this.flags &= ~FL_JUMPRELEASED;
1945 this.flags |= FL_SPAWNING;
1946 } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) {
1947 this.flags &= ~FL_JUMPRELEASED;
1948 if(SpectateNext()) {
1949 TRANSMUTE(Spectator, this);
1951 TRANSMUTE(Observer, this);
1952 PutClientInServer();
1955 } else if(this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229)) {
1956 this.flags &= ~FL_JUMPRELEASED;
1957 if(SpectatePrev()) {
1958 TRANSMUTE(Spectator, this);
1960 TRANSMUTE(Observer, this);
1961 PutClientInServer();
1964 } else if (PHYS_INPUT_BUTTON_ATCK2(this)) {
1965 this.flags &= ~FL_JUMPRELEASED;
1966 TRANSMUTE(Observer, this);
1967 PutClientInServer();
1969 if(!SpectateUpdate())
1970 PutObserverInServer();
1973 if (!(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this))) {
1974 this.flags |= FL_JUMPRELEASED;
1975 if(this.flags & FL_SPAWNING)
1977 this.flags &= ~FL_SPAWNING;
1978 LeaveSpectatorMode();
1982 if(!SpectateUpdate())
1983 PutObserverInServer();
1986 this.flags |= FL_CLIENT | FL_NOTARGET;
1989 void vehicles_enter (entity pl, entity veh);
1992 if (!IS_PLAYER(this))
1999 vehicles_exit(VHEF_NORMAL);
2003 else if(autocvar_g_vehicles_enter)
2005 if(!STAT(FROZEN, this))
2009 entity head, closest_target = world;
2010 head = WarpZone_FindRadius(this.origin, autocvar_g_vehicles_enter_radius, true);
2012 while(head) // find the closest acceptable target to enter
2014 if(head.vehicle_flags & VHF_ISVEHICLE)
2016 if(!head.owner || ((head.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(head.owner, this)))
2017 if(head.takedamage != DAMAGE_NO)
2021 if(vlen(this.origin - head.origin) < vlen(this.origin - closest_target.origin))
2022 { closest_target = head; }
2024 else { closest_target = head; }
2030 if(closest_target) { vehicles_enter(this, closest_target); return; }
2034 // a use key was pressed; call handlers
2035 MUTATOR_CALLHOOK(PlayerUseKey);
2043 Called every frame for each client before the physics are run
2046 .float usekeypressed;
2047 void() nexball_setstatus;
2048 .float last_vehiclecheck;
2050 void PlayerPreThink ()
2053 WarpZone_PlayerPhysics_FixVAngle(this);
2055 STAT(GAMESTARTTIME, this) = game_starttime;
2056 STAT(ROUNDSTARTTIME, this) = round_starttime;
2057 STAT(ALLOW_OLDVORTEXBEAM, this) = autocvar_g_allow_oldvortexbeam;
2058 STAT(LEADLIMIT, this) = autocvar_leadlimit;
2060 STAT(WEAPONSINMAP, this) = weaponsInMap;
2063 // physics frames: update anticheat stuff
2064 anticheat_prethink(this);
2067 if (blockSpectators && frametime) {
2068 // WORKAROUND: only use dropclient in server frames (frametime set).
2069 // Never use it in cl_movement frames (frametime zero).
2070 checkSpectatorBlock();
2073 zoomstate_set = false;
2075 // Check for nameless players
2076 if (isInvisibleString(this.netname)) {
2077 this.netname = strzone(sprintf("Player#%d", this.playerid));
2078 // stuffcmd(this, strcat("name ", this.netname, "\n")); // maybe?
2080 if (this.netname != this.netname_previous) {
2081 if (autocvar_sv_eventlog) {
2082 GameLogEcho(strcat(":name:", ftos(this.playerid), ":", this.netname));
2084 if (this.netname_previous) strunzone(this.netname_previous);
2085 this.netname_previous = strzone(this.netname);
2089 if (this.version_nagtime && this.cvar_g_xonoticversion && time > this.version_nagtime) {
2090 this.version_nagtime = 0;
2091 if (strstrofs(this.cvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(this.cvar_g_xonoticversion, "autobuild", 0) >= 0) {
2093 } else if (strstrofs(autocvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(autocvar_g_xonoticversion, "autobuild", 0) >= 0) {
2095 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2097 int r = vercmp(this.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2098 if (r < 0) { // old client
2099 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2100 } else if (r > 0) { // old server
2101 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, this.cvar_g_xonoticversion);
2107 if (!(this.flags & FL_GODMODE) && this.max_armorvalue)
2109 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_GODMODE_OFF, this.max_armorvalue);
2110 this.max_armorvalue = 0;
2113 if (STAT(FROZEN, this) == 2)
2115 this.revive_progress = bound(0, this.revive_progress + frametime * this.revive_speed, 1);
2116 this.health = max(1, this.revive_progress * start_health);
2117 this.iceblock.alpha = bound(0.2, 1 - this.revive_progress, 1);
2119 if (this.revive_progress >= 1)
2122 else if (STAT(FROZEN, this) == 3)
2124 this.revive_progress = bound(0, this.revive_progress - frametime * this.revive_speed, 1);
2125 this.health = max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * this.revive_progress );
2127 if (this.health < 1)
2130 vehicles_exit(VHEF_RELEASE);
2131 this.event_damage(this, this, this.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, this.origin, '0 0 0');
2133 else if (this.revive_progress <= 0)
2137 MUTATOR_CALLHOOK(PlayerPreThink);
2139 if(autocvar_g_vehicles_enter)
2140 if(time > this.last_vehiclecheck)
2143 if(!STAT(FROZEN, this))
2148 for(veh = world; (veh = findflags(veh, vehicle_flags, VHF_ISVEHICLE)); )
2149 if(vlen(veh.origin - this.origin) < autocvar_g_vehicles_enter_radius)
2151 if(veh.takedamage != DAMAGE_NO)
2152 if((veh.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(veh.owner, this))
2153 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
2155 if(!veh.team || SAME_TEAM(this, veh))
2156 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER);
2157 else if(autocvar_g_vehicles_steal)
2158 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
2160 this.last_vehiclecheck = time + 1;
2163 if(!this.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2165 if(PHYS_INPUT_BUTTON_USE(this) && !this.usekeypressed)
2167 this.usekeypressed = PHYS_INPUT_BUTTON_USE(this);
2170 if (IS_REAL_CLIENT(this))
2171 PrintWelcomeMessage(this);
2173 if (IS_PLAYER(this)) {
2174 CheckRules_Player();
2176 if (intermission_running) {
2177 IntermissionThink();
2181 if (timeout_status == TIMEOUT_ACTIVE) {
2182 // don't allow the player to turn around while game is paused
2183 // FIXME turn this into CSQC stuff
2184 this.v_angle = this.lastV_angle;
2185 this.angles = this.lastV_angle;
2186 this.fixangle = true;
2189 if (frametime) player_powerups();
2191 if (IS_DEAD(this)) {
2192 if (this.personal && g_race_qualifying) {
2193 if (time > this.respawn_time) {
2194 STAT(RESPAWN_TIME, this) = this.respawn_time = time + 1; // only retry once a second
2196 this.impulse = CHIMPULSE_SPEEDRUN.impulse;
2199 if (frametime) player_anim();
2200 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));
2202 if (this.deadflag == DEAD_DYING) {
2203 if ((this.respawn_flags & RESPAWN_FORCE) && !autocvar_g_respawn_delay_max) {
2204 this.deadflag = DEAD_RESPAWNING;
2205 } else if (!button_pressed) {
2206 this.deadflag = DEAD_DEAD;
2208 } else if (this.deadflag == DEAD_DEAD) {
2209 if (button_pressed) {
2210 this.deadflag = DEAD_RESPAWNABLE;
2211 } else if (time >= this.respawn_time_max && (this.respawn_flags & RESPAWN_FORCE)) {
2212 this.deadflag = DEAD_RESPAWNING;
2214 } else if (this.deadflag == DEAD_RESPAWNABLE) {
2215 if (!button_pressed) {
2216 this.deadflag = DEAD_RESPAWNING;
2218 } else if (this.deadflag == DEAD_RESPAWNING) {
2219 if (time > this.respawn_time) {
2220 this.respawn_time = time + 1; // only retry once a second
2221 this.respawn_time_max = this.respawn_time;
2226 ShowRespawnCountdown();
2228 if (this.respawn_flags & RESPAWN_SILENT)
2229 STAT(RESPAWN_TIME, this) = 0;
2230 else if ((this.respawn_flags & RESPAWN_FORCE) && autocvar_g_respawn_delay_max)
2231 STAT(RESPAWN_TIME, this) = this.respawn_time_max;
2233 STAT(RESPAWN_TIME, this) = this.respawn_time;
2236 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2237 if (this.deadflag == DEAD_RESPAWNING && STAT(RESPAWN_TIME, this) > 0)
2238 STAT(RESPAWN_TIME, this) *= -1;
2243 this.prevorigin = this.origin;
2245 bool do_crouch = PHYS_INPUT_BUTTON_CROUCH(this);
2246 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
2247 if (this.hook.state) {
2249 } else if (this.vehicle) {
2251 } else if (STAT(FROZEN, this)) {
2253 } else if ((PS(this).m_weapon == WEP_SHOTGUN || PS(this).m_weapon == WEP_SHOCKWAVE) && this.(weaponentity).wframe == WFRAME_FIRE2 && time < this.(weaponentity).weapon_nextthink) {
2254 // WEAPONTODO: predict
2261 this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, this);
2262 setsize(this, STAT(PL_CROUCH_MIN, this), STAT(PL_CROUCH_MAX, this));
2263 // setanim(this, this.anim_duck, false, true, true); // this anim is BROKEN anyway
2265 } else if (this.crouch) {
2266 tracebox(this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), this.origin, false, this);
2267 if (!trace_startsolid) {
2268 this.crouch = false;
2269 this.view_ofs = STAT(PL_VIEW_OFS, this);
2270 setsize(this, STAT(PL_MIN, this), STAT(PL_MAX, this));
2274 FixPlayermodel(this);
2276 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2279 this.items &= ~this.items_added;
2281 W_WeaponFrame(this);
2283 this.items_added = 0;
2284 if (this.items & ITEM_Jetpack.m_itemid && (this.items & ITEM_JetpackRegen.m_itemid || this.ammo_fuel >= 0.01))
2285 this.items_added |= IT_FUEL;
2287 this.items |= this.items_added;
2292 // WEAPONTODO: Add a weapon request for this
2293 // rot vortex charge to the charge limit
2294 if (WEP_CVAR(vortex, charge_rot_rate) && this.vortex_charge > WEP_CVAR(vortex, charge_limit) && this.vortex_charge_rottime < time)
2295 this.vortex_charge = bound(WEP_CVAR(vortex, charge_limit), this.vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1);
2297 if (frametime) player_anim();
2300 secrets_setstatus();
2303 monsters_setstatus(this);
2305 this.dmg_team = max(0, this.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2307 else if (gameover) {
2308 if (intermission_running) IntermissionThink();
2311 else if (IS_OBSERVER(this)) {
2314 else if (IS_SPEC(this)) {
2318 // WEAPONTODO: Add weapon request for this
2319 if (!zoomstate_set) {
2321 PHYS_INPUT_BUTTON_ZOOM(this) || PHYS_INPUT_BUTTON_ZOOMSCRIPT(this)
2322 || (PHYS_INPUT_BUTTON_ATCK2(this) && PS(this).m_weapon == WEP_VORTEX)
2323 || (PHYS_INPUT_BUTTON_ATCK2(this) && PS(this).m_weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0)
2327 int oldspectatee_status = this.spectatee_status;
2328 if (IS_SPEC(this)) {
2329 this.spectatee_status = etof(this.enemy);
2330 } else if (IS_OBSERVER(this)) {
2331 this.spectatee_status = etof(this);
2333 this.spectatee_status = 0;
2335 if (this.spectatee_status != oldspectatee_status) {
2336 ClientData_Touch(this);
2337 if (g_race || g_cts) race_InitSpectator();
2340 if (this.teamkill_soundtime && time > this.teamkill_soundtime)
2342 this.teamkill_soundtime = 0;
2344 entity e = this.teamkill_soundsource;
2345 entity oldpusher = e.pusher;
2347 PlayerSound(e, playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2348 e.pusher = oldpusher;
2351 if (this.taunt_soundtime && time > this.taunt_soundtime) {
2352 this.taunt_soundtime = 0;
2353 PlayerSound(this, playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2356 target_voicescript_next(this);
2358 // WEAPONTODO: Move into weaponsystem somehow
2359 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2360 if (PS(this).m_weapon == WEP_Null)
2361 this.clip_load = this.clip_size = 0;
2364 void DrownPlayer(entity this)
2369 if (this.waterlevel != WATERLEVEL_SUBMERGED)
2371 if(this.air_finished < time)
2372 PlayerSound(this, playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
2373 this.air_finished = time + autocvar_g_balance_contents_drowndelay;
2376 else if (this.air_finished < time)
2378 if (this.pain_finished < time)
2380 Damage (this, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, this.origin, '0 0 0');
2381 this.pain_finished = time + 0.5;
2390 Called every frame for each client after the physics are run
2393 .float idlekick_lasttimeleft;
2394 void PlayerPostThink ()
2398 if (frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2399 if (IS_REAL_CLIENT(this))
2400 if (IS_PLAYER(this) || sv_maxidle_spectatorsareidle)
2402 if (time - this.parm_idlesince < 1) // instead of (time == this.parm_idlesince) to support sv_maxidle <= 10
2404 if (this.idlekick_lasttimeleft)
2406 this.idlekick_lasttimeleft = 0;
2407 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_IDLING);
2412 float timeleft = ceil(sv_maxidle - (time - this.parm_idlesince));
2413 if (timeleft == min(10, sv_maxidle - 1)) { // - 1 to support sv_maxidle <= 10
2414 if (!this.idlekick_lasttimeleft)
2415 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
2417 if (timeleft <= 0) {
2418 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_KICK_IDLING, this.netname);
2422 else if (timeleft <= 10) {
2423 if (timeleft != this.idlekick_lasttimeleft) {
2424 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, Announcer_PickNumber(CNT_IDLE, timeleft));
2426 this.idlekick_lasttimeleft = timeleft;
2433 //CheckPlayerJump();
2435 if (IS_PLAYER(this)) {
2437 CheckRules_Player();
2439 if (this.impulse) ImpulseCommands(this);
2440 if (intermission_running) return; // intermission or finale
2444 if (this.waypointsprite_attachedforcarrier) {
2445 vector v = healtharmor_maxdamage(this.health, this.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id);
2446 WaypointSprite_UpdateHealth(this.waypointsprite_attachedforcarrier, '1 0 0' * v);
2451 CSQCMODEL_AUTOUPDATE(this);