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/triggers/teleporters.qh"
30 #include "../common/vehicles/all.qh"
32 #include "weapons/hitplot.qh"
33 #include "weapons/weaponsystem.qh"
35 #include "../common/net_notice.qh"
36 #include "../common/physics/player.qh"
38 #include "../common/items/all.qc"
40 #include "../common/mutators/mutator/waypoints/all.qh"
42 #include "../common/triggers/subs.qh"
43 #include "../common/triggers/triggers.qh"
44 #include "../common/triggers/trigger/secret.qh"
46 #include "../common/minigames/sv_minigames.qh"
48 #include "../common/items/inventory.qh"
50 #include "../common/monsters/sv_monsters.qh"
52 #include "../lib/warpzone/server.qh"
55 void send_CSQC_teamnagger() {
56 WriteHeader(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
59 bool ClientData_Send(entity this, entity to, int sf)
61 assert(to == this.owner, return false);
64 if (IS_SPEC(e)) e = e.enemy;
67 if (e.race_completed) sf |= 1; // forced scoreboard
68 if (to.spectatee_status) sf |= 2; // spectator ent number follows
69 if (e.zoomstate) sf |= 4; // zoomed
70 if (e.porto_v_angle_held) sf |= 8; // angles held
72 WriteHeader(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
73 WriteByte(MSG_ENTITY, sf);
77 WriteByte(MSG_ENTITY, to.spectatee_status);
81 WriteAngle(MSG_ENTITY, e.v_angle.x);
82 WriteAngle(MSG_ENTITY, e.v_angle.y);
87 void ClientData_Attach(entity this)
89 Net_LinkEntity(this.clientdata = new_pure(clientdata), false, 0, ClientData_Send);
90 self.clientdata.drawonlytoclient = this;
91 self.clientdata.owner = this;
94 void ClientData_Detach(entity this)
96 remove(this.clientdata);
97 self.clientdata = NULL;
100 void ClientData_Touch(entity e)
102 e.clientdata.SendFlags = 1;
104 // make it spectatable
105 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != e && IS_SPEC(it) && it.enemy == e, LAMBDA(it.clientdata.SendFlags = 1));
108 .string netname_previous;
110 void SetSpectatee(entity player, entity spectatee);
117 Checks if the argument string can be a valid playermodel.
118 Returns a valid one in doubt.
121 string FallbackPlayerModel;
122 string CheckPlayerModel(string plyermodel) {
123 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
125 // note: we cannot summon Don Strunzone here, some player may
126 // still have the model string set. In case anyone manages how
127 // to change a cvar default, we'll have a small leak here.
128 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
130 // only in right path
131 if( substring(plyermodel,0,14) != "models/player/")
132 return FallbackPlayerModel;
133 // only good file extensions
134 if(substring(plyermodel,-4,4) != ".zym")
135 if(substring(plyermodel,-4,4) != ".dpm")
136 if(substring(plyermodel,-4,4) != ".iqm")
137 if(substring(plyermodel,-4,4) != ".md3")
138 if(substring(plyermodel,-4,4) != ".psk")
139 return FallbackPlayerModel;
140 // forbid the LOD models
141 if(substring(plyermodel, -9,5) == "_lod1")
142 return FallbackPlayerModel;
143 if(substring(plyermodel, -9,5) == "_lod2")
144 return FallbackPlayerModel;
145 if(plyermodel != strtolower(plyermodel))
146 return FallbackPlayerModel;
147 // also, restrict to server models
148 if(autocvar_sv_servermodelsonly)
150 if(!fexists(plyermodel))
151 return FallbackPlayerModel;
156 void setplayermodel(entity e, string modelname)
158 precache_model(modelname);
159 _setmodel(e, modelname);
160 player_setupanimsformodel();
163 void FixPlayermodel(entity player);
164 /** putting a client as observer in the server */
165 void PutObserverInServer()
168 bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver);
169 PlayerState_detach(this);
171 if (IS_PLAYER(this) && this.health >= 1) {
173 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
177 entity spot = SelectSpawnPoint(true);
178 if (!spot) LOG_FATAL("No spawnpoints for observers?!?");
179 this.angles = spot.angles;
181 this.fixangle = true;
182 // offset it so that the spectator spawns higher off the ground, looks better this way
183 setorigin(this, spot.origin + STAT(PL_VIEW_OFS, NULL));
184 this.prevorigin = this.origin;
185 if (IS_REAL_CLIENT(this))
188 WriteByte(MSG_ONE, SVC_SETVIEW);
189 WriteEntity(MSG_ONE, this);
191 // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
192 // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
193 setmodel(this, MDL_Null);
194 setsize(this, STAT(PL_CROUCH_MIN, NULL), STAT(PL_CROUCH_MAX, NULL));
195 this.view_ofs = '0 0 0';
198 RemoveGrapplingHook(this);
199 Portal_ClearAll(this);
205 PS_GR_P_ADDVAL(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
209 if (this.vehicle) vehicles_exit(VHEF_RELEASE);
211 WaypointSprite_PlayerDead(this);
213 if (mutator_returnvalue) {
214 // mutator prevents resetting teams+score
216 this.team = -1; // move this as it is needed to log the player spectating in eventlog
217 this.frags = FRAGS_SPECTATOR;
218 PlayerScore_Clear(this); // clear scores when needed
221 if (this.killcount != FRAGS_SPECTATOR)
223 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_SPECTATE, this.netname);
224 if(!intermission_running)
225 if(autocvar_g_chat_nospectators == 1 || (!(warmup_stage || gameover) && autocvar_g_chat_nospectators == 2))
226 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CHAT_NOSPECTATORS);
228 if(this.just_joined == false) {
229 LogTeamchange(this.playerid, -1, 4);
231 this.just_joined = false;
234 accuracy_resend(this);
236 this.spectatortime = time;
237 this.bot_attack = false;
238 this.hud = HUD_NORMAL;
239 this.classname = STR_OBSERVER;
240 this.iscreature = false;
241 this.teleportable = TELEPORT_SIMPLE;
242 this.damagedbycontents = false;
243 this.health = FRAGS_SPECTATOR;
244 this.takedamage = DAMAGE_NO;
245 this.solid = SOLID_NOT;
246 this.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink
247 this.flags = FL_CLIENT | FL_NOTARGET;
248 this.armorvalue = 666;
250 this.armorvalue = autocvar_g_balance_armor_start;
251 this.pauserotarmor_finished = 0;
252 this.pauserothealth_finished = 0;
253 this.pauseregen_finished = 0;
254 this.damageforcescale = 0;
256 this.respawn_flags = 0;
257 this.respawn_time = 0;
258 this.stat_respawn_time = 0;
263 this.pain_finished = 0;
264 this.strength_finished = 0;
265 this.invincible_finished = 0;
266 this.superweapons_finished = 0;
269 this.think = func_null;
272 this.deadflag = DEAD_NO;
274 this.revival_time = 0;
277 this.weapons = '0 0 0';
278 this.drawonlytoclient = this;
280 this.weaponname = "";
281 this.weaponmodel = "";
282 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
284 this.weaponentities[slot] = NULL;
286 this.exteriorweaponentity = NULL;
287 this.killcount = FRAGS_SPECTATOR;
288 this.velocity = '0 0 0';
289 this.avelocity = '0 0 0';
290 this.punchangle = '0 0 0';
291 this.punchvector = '0 0 0';
292 this.oldvelocity = this.velocity;
293 this.fire_endtime = -1;
294 this.event_damage = func_null;
297 int player_getspecies(entity this)
299 get_model_parameters(this.model, this.skin);
300 int s = get_model_parameters_species;
301 get_model_parameters(string_null, 0);
302 if (s < 0) return SPECIES_HUMAN;
306 .float model_randomizer;
307 void FixPlayermodel(entity player)
309 string defaultmodel = "";
311 if(autocvar_sv_defaultcharacter)
315 string s = Static_Team_ColorName_Lower(player.team);
318 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
319 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
323 if(defaultmodel == "")
325 defaultmodel = autocvar_sv_defaultplayermodel;
326 defaultskin = autocvar_sv_defaultplayerskin;
329 int n = tokenize_console(defaultmodel);
332 defaultmodel = argv(floor(n * player.model_randomizer));
333 // However, do NOT randomize if the player-selected model is in the list.
334 for (int i = 0; i < n; ++i)
335 if ((argv(i) == player.playermodel && defaultskin == stof(player.playerskin)) || argv(i) == strcat(player.playermodel, ":", player.playerskin))
336 defaultmodel = argv(i);
339 int i = strstrofs(defaultmodel, ":", 0);
342 defaultskin = stof(substring(defaultmodel, i+1, -1));
343 defaultmodel = substring(defaultmodel, 0, i);
346 MUTATOR_CALLHOOK(FixPlayermodel, defaultmodel, defaultskin);
347 defaultmodel = ret_string;
348 defaultskin = ret_int;
352 if(defaultmodel != "")
354 if (defaultmodel != player.model)
356 vector m1 = player.mins;
357 vector m2 = player.maxs;
358 setplayermodel (player, defaultmodel);
359 setsize (player, m1, m2);
363 oldskin = player.skin;
364 player.skin = defaultskin;
366 if (player.playermodel != player.model || player.playermodel == "")
368 player.playermodel = CheckPlayerModel(player.playermodel); // this is never "", so no endless loop
369 vector m1 = player.mins;
370 vector m2 = player.maxs;
371 setplayermodel (player, player.playermodel);
372 setsize (player, m1, m2);
376 oldskin = player.skin;
377 player.skin = stof(player.playerskin);
380 if(chmdl || oldskin != player.skin) // model or skin has changed
382 player.species = player_getspecies(player); // update species
386 if(strlen(autocvar_sv_defaultplayercolors))
387 if(player.clientcolors != stof(autocvar_sv_defaultplayercolors))
388 setcolor(player, stof(autocvar_sv_defaultplayercolors));
392 /** Called when a client spawns in the server */
393 void PutClientInServer()
396 if (IS_BOT_CLIENT(this)) {
397 this.classname = STR_PLAYER;
398 } else if (IS_REAL_CLIENT(this)) {
400 WriteByte(MSG_ONE, SVC_SETVIEW);
401 WriteEntity(MSG_ONE, this);
404 this.classname = STR_OBSERVER;
407 SetSpectatee(this, NULL);
412 MUTATOR_CALLHOOK(PutClientInServer, this);
414 if (IS_OBSERVER(this)) {
415 PutObserverInServer();
416 } else if (IS_PLAYER(this)) {
417 PlayerState_attach(this);
418 accuracy_resend(this);
421 JoinBestTeam(this, false, true);
423 entity spot = SelectSpawnPoint(false);
425 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
426 return; // spawn failed
429 this.classname = STR_PLAYER;
430 this.wasplayer = true;
431 this.iscreature = true;
432 this.teleportable = TELEPORT_NORMAL;
433 this.damagedbycontents = true;
434 this.movetype = MOVETYPE_WALK;
435 this.solid = SOLID_SLIDEBOX;
436 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
437 if (autocvar_g_playerclip_collisions)
438 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
439 if (IS_BOT_CLIENT(this) && autocvar_g_botclip_collisions)
440 this.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
441 this.frags = FRAGS_PLAYER;
442 if (INDEPENDENT_PLAYERS) MAKE_INDEPENDENT_PLAYER(this);
443 this.flags = FL_CLIENT | FL_PICKUPITEMS;
444 if (autocvar__notarget)
445 this.flags |= FL_NOTARGET;
446 this.takedamage = DAMAGE_AIM;
447 this.effects = EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
451 this.ammo_shells = warmup_start_ammo_shells;
452 this.ammo_nails = warmup_start_ammo_nails;
453 this.ammo_rockets = warmup_start_ammo_rockets;
454 this.ammo_cells = warmup_start_ammo_cells;
455 this.ammo_plasma = warmup_start_ammo_plasma;
456 this.ammo_fuel = warmup_start_ammo_fuel;
457 this.health = warmup_start_health;
458 this.armorvalue = warmup_start_armorvalue;
459 this.weapons = WARMUP_START_WEAPONS;
461 this.ammo_shells = start_ammo_shells;
462 this.ammo_nails = start_ammo_nails;
463 this.ammo_rockets = start_ammo_rockets;
464 this.ammo_cells = start_ammo_cells;
465 this.ammo_plasma = start_ammo_plasma;
466 this.ammo_fuel = start_ammo_fuel;
467 this.health = start_health;
468 this.armorvalue = start_armorvalue;
469 this.weapons = start_weapons;
472 this.superweapons_finished = (this.weapons & WEPSET_SUPERWEAPONS) ? time + autocvar_g_balance_superweapons_time : 0;
474 this.items = start_items;
476 this.spawnshieldtime = time + autocvar_g_spawnshieldtime;
477 this.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
478 this.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
479 this.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
480 this.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
481 // extend the pause of rotting if client was reset at the beginning of the countdown
482 if (!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
483 float f = game_starttime - time;
484 this.spawnshieldtime += f;
485 this.pauserotarmor_finished += f;
486 this.pauserothealth_finished += f;
487 this.pauseregen_finished += f;
489 this.damageforcescale = 2;
491 this.respawn_flags = 0;
492 this.respawn_time = 0;
493 this.stat_respawn_time = 0;
494 this.scale = autocvar_sv_player_scale;
497 this.pain_finished = 0;
499 this.think = func_null; // players have no think function
502 this.ballistics_density = autocvar_g_ballistics_density_player;
504 this.deadflag = DEAD_NO;
506 this.angles = spot.angles;
507 this.angles_z = 0; // never spawn tilted even if the spot says to
508 if (IS_BOT_CLIENT(this))
509 this.v_angle = this.angles;
510 this.fixangle = true; // turn this way immediately
511 this.oldvelocity = this.velocity = '0 0 0';
512 this.avelocity = '0 0 0';
513 this.punchangle = '0 0 0';
514 this.punchvector = '0 0 0';
516 this.strength_finished = 0;
517 this.invincible_finished = 0;
518 this.fire_endtime = -1;
519 this.revival_time = 0;
520 this.air_finished = time + 12;
522 entity spawnevent = new_pure(spawnevent);
523 spawnevent.owner = this;
524 Net_LinkEntity(spawnevent, false, 0.5, SpawnEvent_Send);
526 // Cut off any still running player sounds.
527 stopsound(this, CH_PLAYER_SINGLE);
530 FixPlayermodel(this);
531 this.drawonlytoclient = NULL;
534 this.view_ofs = STAT(PL_VIEW_OFS, NULL);
535 setsize(this, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
536 this.spawnorigin = spot.origin;
537 setorigin(this, spot.origin + '0 0 1' * (1 - this.mins.z - 24));
538 // don't reset back to last position, even if new position is stuck in solid
539 this.oldorigin = this.origin;
540 this.prevorigin = this.origin;
541 this.lastteleporttime = time; // prevent insane speeds due to changing origin
542 this.hud = HUD_NORMAL;
544 this.event_damage = PlayerDamage;
546 this.bot_attack = true;
547 this.monster_attack = true;
549 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_JUMP(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
551 if (this.killcount == FRAGS_SPECTATOR) {
552 PlayerScore_Clear(this);
556 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
558 CL_SpawnWeaponentity(this, weaponentities[slot]);
560 this.alpha = default_player_alpha;
561 this.colormod = '1 1 1' * autocvar_g_player_brightness;
562 this.exteriorweaponentity.alpha = default_weapon_alpha;
564 this.speedrunning = false;
566 target_voicescript_clear(this);
568 // reset fields the weapons may use
569 FOREACH(Weapons, true, LAMBDA(
570 it.wr_resetplayer(it);
571 // reload all reloadable weapons
572 if (it.spawnflags & WEP_FLAG_RELOADABLE) {
573 this.weapon_load[it.m_id] = it.reloading_ammo;
578 string s = spot.target;
579 spot.target = string_null;
580 WITH(entity, activator, this, LAMBDA(
581 WITH(entity, self, spot, SUB_UseTargets())
588 MUTATOR_CALLHOOK(PlayerSpawn, spot);
590 if (autocvar_spawn_debug)
592 sprint(this, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
593 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
596 PS(this).m_switchweapon = w_getbestweapon(this);
597 this.cnt = -1; // W_LastWeapon will not complain
598 PS(this).m_weapon = WEP_Null;
599 this.weaponname = "";
600 PS(this).m_switchingweapon = WEP_Null;
602 if (!warmup_stage && !this.alivetime)
603 this.alivetime = time;
609 void ClientInit_misc();
611 .float ebouncefactor, ebouncestop; // electro's values
612 // TODO do we need all these fields, or should we stop autodetecting runtime
613 // changes and just have a console command to update this?
614 bool ClientInit_SendEntity(entity this, entity to, int sf)
616 WriteHeader(MSG_ENTITY, _ENT_CLIENT_INIT);
619 // MSG_INIT replacement
620 // TODO: make easier to use
622 W_PROP_reload(MSG_ONE, to);
624 MUTATOR_CALLHOOK(Ent_Init);
626 void ClientInit_misc()
628 int channel = MSG_ONE;
629 WriteHeader(channel, ENT_CLIENT_INIT);
630 WriteByte(channel, g_nexball_meter_period * 32);
631 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[0]));
632 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[1]));
633 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[2]));
634 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[3]));
635 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[0]));
636 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[1]));
637 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[2]));
638 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[3]));
640 if(sv_foginterval && world.fog != "")
641 WriteString(channel, world.fog);
643 WriteString(channel, "");
644 WriteByte(channel, self.count * 255.0); // g_balance_armor_blockpercent
645 WriteByte(channel, serverflags); // client has to know if it should zoom or not
646 WriteCoord(channel, autocvar_g_trueaim_minrange);
649 void ClientInit_CheckUpdate()
651 self.nextthink = time;
652 if(self.count != autocvar_g_balance_armor_blockpercent)
654 self.count = autocvar_g_balance_armor_blockpercent;
659 void ClientInit_Spawn()
662 entity e = new_pure(clientinit);
663 e.think = ClientInit_CheckUpdate;
664 Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
666 WITH(entity, self, e, ClientInit_CheckUpdate());
676 // initialize parms for a new player
677 parm1 = -(86400 * 366);
679 MUTATOR_CALLHOOK(SetNewParms);
687 void SetChangeParms ()
689 // save parms for level change
690 parm1 = self.parm_idlesince - time;
692 MUTATOR_CALLHOOK(SetChangeParms);
700 void DecodeLevelParms(entity this)
703 this.parm_idlesince = parm1;
704 if (this.parm_idlesince == -(86400 * 366))
705 this.parm_idlesince = time;
707 // whatever happens, allow 60 seconds of idling directly after connect for map loading
708 this.parm_idlesince = max(this.parm_idlesince, time - sv_maxidle + 60);
710 MUTATOR_CALLHOOK(DecodeLevelParms);
717 Called when a client types 'kill' in the console
721 .float clientkill_nexttime;
722 void ClientKill_Now_TeamChange(entity this)
724 if(this.killindicator_teamchange == -1)
726 JoinBestTeam( this, false, true );
728 else if(this.killindicator_teamchange == -2)
731 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
732 WITH(entity, self, this, PutObserverInServer());
735 WITH(entity, self, this, SV_ChangeTeam(this.killindicator_teamchange - 1));
736 this.killindicator_teamchange = 0;
739 void ClientKill_Now()
743 vehicles_exit(VHEF_RELEASE);
744 if(!self.killindicator_teamchange)
746 self.vehicle_health = -1;
747 Damage(self, self, self, 1 , DEATH_KILL.m_id, self.origin, '0 0 0');
751 if(self.killindicator && !wasfreed(self.killindicator))
752 remove(self.killindicator);
754 self.killindicator = world;
756 if(self.killindicator_teamchange)
757 ClientKill_Now_TeamChange(self);
760 Damage(self, self, self, 100000, DEATH_KILL.m_id, self.origin, '0 0 0');
762 // now I am sure the player IS dead
764 void KillIndicator_Think()
768 self.owner.killindicator = world;
773 if (self.owner.alpha < 0 && !self.owner.vehicle)
775 self.owner.killindicator = world;
782 WITH(entity, self, self.owner, ClientKill_Now());
785 else if(g_cts && self.health == 1) // health == 1 means that it's silent
787 self.nextthink = time + 1;
793 setmodel(self, MDL_NUM(self.cnt));
794 if(IS_REAL_CLIENT(self.owner))
797 { Send_Notification(NOTIF_ONE, self.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, self.cnt)); }
799 self.nextthink = time + 1;
804 float clientkilltime;
805 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
814 killtime = autocvar_g_balance_kill_delay;
816 if(g_race_qualifying || g_cts)
819 if(MUTATOR_CALLHOOK(ClientKill, self, killtime))
822 self.killindicator_teamchange = targetteam;
824 if(!self.killindicator)
828 killtime = max(killtime, self.clientkill_nexttime - time);
829 self.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
832 if(killtime <= 0 || !IS_PLAYER(self) || IS_DEAD(self))
838 starttime = max(time, clientkilltime);
840 self.killindicator = spawn();
841 self.killindicator.owner = self;
842 self.killindicator.scale = 0.5;
843 setattachment(self.killindicator, self, "");
844 setorigin(self.killindicator, '0 0 52');
845 self.killindicator.think = KillIndicator_Think;
846 self.killindicator.nextthink = starttime + (self.lip) * 0.05;
847 clientkilltime = max(clientkilltime, self.killindicator.nextthink + 0.05);
848 self.killindicator.cnt = ceil(killtime);
849 self.killindicator.count = bound(0, ceil(killtime), 10);
850 //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
852 for(e = world; (e = find(e, classname, "body")) != world; )
856 e.killindicator = spawn();
857 e.killindicator.owner = e;
858 e.killindicator.scale = 0.5;
859 setattachment(e.killindicator, e, "");
860 setorigin(e.killindicator, '0 0 52');
861 e.killindicator.think = KillIndicator_Think;
862 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
863 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
864 e.killindicator.cnt = ceil(killtime);
869 if(self.killindicator)
871 if(targetteam == 0) // just die
873 self.killindicator.colormod = '0 0 0';
874 if(IS_REAL_CLIENT(self))
875 if(self.killindicator.cnt > 0)
876 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, self.killindicator.cnt);
878 else if(targetteam == -1) // auto
880 self.killindicator.colormod = '0 1 0';
881 if(IS_REAL_CLIENT(self))
882 if(self.killindicator.cnt > 0)
883 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, self.killindicator.cnt);
885 else if(targetteam == -2) // spectate
887 self.killindicator.colormod = '0.5 0.5 0.5';
888 if(IS_REAL_CLIENT(self))
889 if(self.killindicator.cnt > 0)
890 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, self.killindicator.cnt);
894 self.killindicator.colormod = Team_ColorRGB(targetteam);
895 if(IS_REAL_CLIENT(self))
896 if(self.killindicator.cnt > 0)
897 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE), self.killindicator.cnt);
906 if(self.player_blocked) return;
907 if(STAT(FROZEN, self)) return;
909 ClientKill_TeamChange(0);
912 void FixClientCvars(entity e)
914 // send prediction settings to the client
915 stuffcmd(e, "\nin_bindmap 0 0\n");
916 if(autocvar_g_antilag == 3) // client side hitscan
917 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
918 if(autocvar_sv_gentle)
919 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
921 MUTATOR_CALLHOOK(FixClientCvars, e);
924 float PlayerInIDList(entity p, string idlist)
929 // NOTE: we do NOT check crypto_idfp_signed here, an unsigned ID is fine too for this
933 // this function allows abbreviated player IDs too!
934 n = tokenize_console(idlist);
935 for(i = 0; i < n; ++i)
938 if(s == substring(p.crypto_idfp, 0, strlen(s)))
945 #ifdef DP_EXT_PRECONNECT
950 Called once (not at each match start) when a client begins a connection to the server
953 void ClientPreConnect ()
955 if(autocvar_sv_eventlog)
957 GameLogEcho(sprintf(":connect:%d:%d:%s",
960 ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot")
970 Called when a client connects to the server
976 if (Ban_MaybeEnforceBanOnce(this)) return;
977 assert(!IS_CLIENT(this), return);
978 assert(player_count >= 0, player_count = 0);
979 this.classname = "player_joining";
980 this.flags = FL_CLIENT;
983 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_WATERMARK, WATERMARK);
985 this.version_nagtime = time + 10 + random() * 10;
987 ClientState_attach(this);
989 // identify the right forced team
990 if (autocvar_g_campaign)
992 if (IS_REAL_CLIENT(this)) // only players, not bots
994 switch (autocvar_g_campaign_forceteam)
996 case 1: this.team_forced = NUM_TEAM_1; break;
997 case 2: this.team_forced = NUM_TEAM_2; break;
998 case 3: this.team_forced = NUM_TEAM_3; break;
999 case 4: this.team_forced = NUM_TEAM_4; break;
1000 default: this.team_forced = 0;
1004 else if (PlayerInIDList(this, autocvar_g_forced_team_red)) this.team_forced = NUM_TEAM_1;
1005 else if (PlayerInIDList(this, autocvar_g_forced_team_blue)) this.team_forced = NUM_TEAM_2;
1006 else if (PlayerInIDList(this, autocvar_g_forced_team_yellow)) this.team_forced = NUM_TEAM_3;
1007 else if (PlayerInIDList(this, autocvar_g_forced_team_pink)) this.team_forced = NUM_TEAM_4;
1008 else switch (autocvar_g_forced_team_otherwise)
1010 default: this.team_forced = 0; break;
1011 case "red": this.team_forced = NUM_TEAM_1; break;
1012 case "blue": this.team_forced = NUM_TEAM_2; break;
1013 case "yellow": this.team_forced = NUM_TEAM_3; break;
1014 case "pink": this.team_forced = NUM_TEAM_4; break;
1017 this.team_forced = -1;
1020 if (!teamplay && this.team_forced > 0) this.team_forced = 0;
1022 JoinBestTeam(this, false, false); // if the team number is valid, keep it
1024 if (autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) {
1025 this.classname = STR_OBSERVER;
1027 if (!teamplay || autocvar_g_balance_teams)
1029 this.classname = STR_PLAYER;
1030 campaign_bots_may_start = 1;
1034 this.classname = STR_OBSERVER; // do it anyway
1038 this.playerid = ++playerid_last;
1040 PlayerStats_GameReport_AddEvent(sprintf("kills-%d", this.playerid));
1042 // always track bots, don't ask for cl_allow_uidtracking
1043 if (IS_BOT_CLIENT(this)) PlayerStats_GameReport_AddPlayer(this);
1045 if (autocvar_sv_eventlog)
1046 GameLogEcho(strcat(":join:", ftos(this.playerid), ":", ftos(etof(this)), ":", ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot"), ":", this.netname));
1048 LogTeamchange(this.playerid, this.team, 1);
1050 this.just_joined = true; // stop spamming the eventlog with additional lines when the client connects
1052 this.netname_previous = strzone(this.netname);
1054 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && IS_PLAYER(this)) ? APP_TEAM_ENT(this, INFO_JOIN_CONNECT_TEAM) : INFO_JOIN_CONNECT), this.netname);
1056 stuffcmd(this, clientstuff, "\n");
1057 stuffcmd(this, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1059 FixClientCvars(this);
1061 // get version info from player
1062 stuffcmd(this, "cmd clientversion $gameversion\n");
1064 // notify about available teams
1067 CheckAllowedTeams(this);
1069 if (c1 >= 0) t |= BIT(0);
1070 if (c2 >= 0) t |= BIT(1);
1071 if (c3 >= 0) t |= BIT(2);
1072 if (c4 >= 0) t |= BIT(3);
1073 stuffcmd(this, sprintf("set _teams_available %d\n", t));
1077 stuffcmd(this, "set _teams_available 0\n");
1080 bot_relinkplayerlist();
1082 this.spectatortime = time;
1083 if (blockSpectators)
1085 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1088 this.jointime = time;
1089 this.allowed_timeouts = autocvar_sv_timeout_number;
1091 if (IS_REAL_CLIENT(this))
1093 if (!autocvar_g_campaign)
1095 this.motd_actived_time = -1;
1096 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1099 if (g_weaponarena_weapons == WEPSET(TUBA))
1100 stuffcmd(this, "cl_cmd settemp chase_active 1\n");
1103 if (!sv_foginterval && world.fog != "")
1104 stuffcmd(this, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1106 if (autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)))
1107 if (!g_ca && !g_cts && !g_race) // teamnagger is currently bad for ca, race & cts
1108 send_CSQC_teamnagger();
1110 CSQCMODEL_AUTOINIT(this);
1112 this.model_randomizer = random();
1114 if (IS_REAL_CLIENT(this))
1115 sv_notice_join(this);
1117 FOREACH_ENTITY_FLOAT(init_for_player_needed, true, {
1118 WITH(entity, self, it, it.init_for_player(it));
1121 MUTATOR_CALLHOOK(ClientConnect, this);
1127 Called when a client disconnects from the server
1130 .entity chatbubbleentity;
1132 void ClientDisconnect()
1135 assert(IS_CLIENT(this), return);
1137 PlayerStats_GameReport_FinalizePlayer(this);
1138 if (this.vehicle) vehicles_exit(VHEF_RELEASE);
1139 if (this.active_minigame) part_minigame(this);
1140 if (IS_PLAYER(this)) Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
1142 if (autocvar_sv_eventlog)
1143 GameLogEcho(strcat(":part:", ftos(this.playerid)));
1145 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
1147 MUTATOR_CALLHOOK(ClientDisconnect);
1149 ClientState_detach(this);
1151 Portal_ClearAll(self);
1155 RemoveGrapplingHook(self);
1157 // Here, everything has been done that requires this player to be a client.
1159 self.flags &= ~FL_CLIENT;
1161 if (this.chatbubbleentity) remove(this.chatbubbleentity);
1162 if (this.killindicator) remove(this.killindicator);
1164 WaypointSprite_PlayerGone();
1166 bot_relinkplayerlist();
1168 if (self.netname_previous) strunzone(self.netname_previous);
1169 if (self.clientstatus) strunzone(self.clientstatus);
1170 if (self.weaponorder_byimpulse) strunzone(self.weaponorder_byimpulse);
1171 if (self.personal) remove(self.personal);
1175 if (vote_called && IS_REAL_CLIENT(this)) VoteCount(false);
1178 void ChatBubbleThink()
1180 self.nextthink = time;
1181 if ((self.owner.alpha < 0) || self.owner.chatbubbleentity != self)
1183 if(self.owner) // but why can that ever be world?
1184 self.owner.chatbubbleentity = world;
1191 if ( !IS_DEAD(self.owner) && IS_PLAYER(self.owner) )
1193 if ( self.owner.active_minigame )
1194 self.mdl = "models/sprites/minigame_busy.iqm";
1195 else if (PHYS_INPUT_BUTTON_CHAT(self.owner))
1196 self.mdl = "models/misc/chatbubble.spr";
1199 if ( self.model != self.mdl )
1200 _setmodel(self, self.mdl);
1204 void UpdateChatBubble()
1208 // spawn a chatbubble entity if needed
1209 if (!self.chatbubbleentity)
1211 self.chatbubbleentity = new(chatbubbleentity);
1212 self.chatbubbleentity.owner = self;
1213 self.chatbubbleentity.exteriormodeltoclient = self;
1214 self.chatbubbleentity.think = ChatBubbleThink;
1215 self.chatbubbleentity.nextthink = time;
1216 setmodel(self.chatbubbleentity, MDL_CHAT); // precision set below
1217 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1218 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1219 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1220 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1221 //self.chatbubbleentity.model = "";
1222 self.chatbubbleentity.effects = EF_LOWPRECISION;
1227 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1228 // added to the model skins
1229 /*void UpdateColorModHack()
1232 c = self.clientcolors & 15;
1233 // LordHavoc: only bothering to support white, green, red, yellow, blue
1234 if (!teamplay) self.colormod = '0 0 0';
1235 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1236 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1237 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1238 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1239 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1240 else self.colormod = '1 1 1';
1245 if(self.alpha >= 0 && autocvar_g_respawn_ghosts)
1247 self.solid = SOLID_NOT;
1248 self.takedamage = DAMAGE_NO;
1249 self.movetype = MOVETYPE_FLY;
1250 self.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1251 self.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1252 self.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1253 Send_Effect(EFFECT_RESPAWN_GHOST, self.origin, '0 0 0', 1);
1254 if(autocvar_g_respawn_ghosts_maxtime)
1255 SUB_SetFade (self, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1260 self.effects |= EF_NODRAW; // prevent another CopyBody
1261 PutClientInServer();
1264 void play_countdown(float finished, string samp)
1266 if(IS_REAL_CLIENT(self))
1267 if(floor(finished - time - frametime) != floor(finished - time))
1268 if(finished - time < 6)
1269 _sound (self, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
1272 void player_powerups ()
1274 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1275 int items_prev = self.items;
1277 if((self.items & IT_USING_JETPACK) && !IS_DEAD(self) && !gameover)
1278 self.modelflags |= MF_ROCKET;
1280 self.modelflags &= ~MF_ROCKET;
1282 self.effects &= ~(EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1284 if((self.alpha < 0 || IS_DEAD(self)) && !self.vehicle) // don't apply the flags if the player is gibbed
1287 Fire_ApplyDamage(self);
1288 Fire_ApplyEffect(self);
1292 if (self.items & ITEM_Strength.m_itemid)
1294 play_countdown(self.strength_finished, SND(POWEROFF));
1295 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1296 if (time > self.strength_finished)
1298 self.items = self.items - (self.items & ITEM_Strength.m_itemid);
1299 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, self.netname);
1300 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
1305 if (time < self.strength_finished)
1307 self.items = self.items | ITEM_Strength.m_itemid;
1308 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, self.netname);
1309 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_STRENGTH);
1312 if (self.items & ITEM_Shield.m_itemid)
1314 play_countdown(self.invincible_finished, SND(POWEROFF));
1315 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1316 if (time > self.invincible_finished)
1318 self.items = self.items - (self.items & ITEM_Shield.m_itemid);
1319 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, self.netname);
1320 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
1325 if (time < self.invincible_finished)
1327 self.items = self.items | ITEM_Shield.m_itemid;
1328 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, self.netname);
1329 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SHIELD);
1332 if (self.items & IT_SUPERWEAPON)
1334 if (!(self.weapons & WEPSET_SUPERWEAPONS))
1336 self.superweapons_finished = 0;
1337 self.items = self.items - (self.items & IT_SUPERWEAPON);
1338 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, self.netname);
1339 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1341 else if (self.items & IT_UNLIMITED_SUPERWEAPONS)
1343 // don't let them run out
1347 play_countdown(self.superweapons_finished, SND(POWEROFF));
1348 if (time > self.superweapons_finished)
1350 self.items = self.items - (self.items & IT_SUPERWEAPON);
1351 self.weapons &= ~WEPSET_SUPERWEAPONS;
1352 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, self.netname);
1353 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1357 else if(self.weapons & WEPSET_SUPERWEAPONS)
1359 if (time < self.superweapons_finished || (self.items & IT_UNLIMITED_SUPERWEAPONS))
1361 self.items = self.items | IT_SUPERWEAPON;
1362 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, self.netname);
1363 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1367 self.superweapons_finished = 0;
1368 self.weapons &= ~WEPSET_SUPERWEAPONS;
1373 self.superweapons_finished = 0;
1377 if(autocvar_g_nodepthtestplayers)
1378 self.effects = self.effects | EF_NODEPTHTEST;
1380 if(autocvar_g_fullbrightplayers)
1381 self.effects = self.effects | EF_FULLBRIGHT;
1383 if (time >= game_starttime)
1384 if (time < self.spawnshieldtime)
1385 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1387 MUTATOR_CALLHOOK(PlayerPowerups, self, items_prev);
1390 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1392 if(current > stable)
1394 else if(current > stable - 0.25) // when close enough, "snap"
1397 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1400 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1402 if(current < stable)
1404 else if(current < stable + 0.25) // when close enough, "snap"
1407 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1410 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1412 if(current > rotstable)
1414 if(rotframetime > 0)
1416 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1417 current = max(rotstable, current - rotlinear * rotframetime);
1420 else if(current < regenstable)
1422 if(regenframetime > 0)
1424 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1425 current = min(regenstable, current + regenlinear * regenframetime);
1435 void player_regen ()
1437 float max_mod, regen_mod, rot_mod, limit_mod;
1438 max_mod = regen_mod = rot_mod = limit_mod = 1;
1439 regen_mod_max = max_mod;
1440 regen_mod_regen = regen_mod;
1441 regen_mod_rot = rot_mod;
1442 regen_mod_limit = limit_mod;
1444 regen_health = autocvar_g_balance_health_regen;
1445 regen_health_linear = autocvar_g_balance_health_regenlinear;
1446 regen_health_rot = autocvar_g_balance_health_rot;
1447 regen_health_rotlinear = autocvar_g_balance_health_rotlinear;
1448 regen_health_stable = autocvar_g_balance_health_regenstable;
1449 regen_health_rotstable = autocvar_g_balance_health_rotstable;
1450 if(!MUTATOR_CALLHOOK(PlayerRegen))
1451 if(!STAT(FROZEN, self))
1453 float mina, maxa, limith, limita;
1454 maxa = autocvar_g_balance_armor_rotstable;
1455 mina = autocvar_g_balance_armor_regenstable;
1456 limith = autocvar_g_balance_health_limit;
1457 limita = autocvar_g_balance_armor_limit;
1459 max_mod = regen_mod_max;
1460 regen_mod = regen_mod_regen;
1461 rot_mod = regen_mod_rot;
1462 limit_mod = regen_mod_limit;
1464 regen_health_rotstable = regen_health_rotstable * max_mod;
1465 regen_health_stable = regen_health_stable * max_mod;
1466 limith = limith * limit_mod;
1467 limita = limita * limit_mod;
1469 self.armorvalue = CalcRotRegen(self.armorvalue, mina, autocvar_g_balance_armor_regen, autocvar_g_balance_armor_regenlinear, regen_mod * frametime * (time > self.pauseregen_finished), maxa, autocvar_g_balance_armor_rot, autocvar_g_balance_armor_rotlinear, rot_mod * frametime * (time > self.pauserotarmor_finished), limita);
1470 self.health = CalcRotRegen(self.health, regen_health_stable, regen_health, regen_health_linear, regen_mod * frametime * (time > self.pauseregen_finished), regen_health_rotstable, regen_health_rot, regen_health_rotlinear, rot_mod * frametime * (time > self.pauserothealth_finished), limith);
1473 // if player rotted to death... die!
1474 // check this outside above checks, as player may still be able to rot to death
1478 vehicles_exit(VHEF_RELEASE);
1479 if(self.event_damage)
1480 self.event_damage(self, self, self, 1, DEATH_ROT.m_id, self.origin, '0 0 0');
1483 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
1485 float minf, maxf, limitf;
1487 maxf = autocvar_g_balance_fuel_rotstable;
1488 minf = autocvar_g_balance_fuel_regenstable;
1489 limitf = autocvar_g_balance_fuel_limit;
1491 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, frametime * (time > self.pauseregen_finished) * ((self.items & ITEM_JetpackRegen.m_itemid) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > self.pauserotfuel_finished), limitf);
1495 float zoomstate_set;
1496 void SetZoomState(float z)
1498 if(z != self.zoomstate)
1501 ClientData_Touch(self);
1506 void GetPressedKeys()
1509 MUTATOR_CALLHOOK(GetPressedKeys);
1510 int keys = this.pressedkeys;
1511 keys = BITSET(keys, KEY_FORWARD, this.movement.x > 0);
1512 keys = BITSET(keys, KEY_BACKWARD, this.movement.x < 0);
1513 keys = BITSET(keys, KEY_RIGHT, this.movement.y > 0);
1514 keys = BITSET(keys, KEY_LEFT, this.movement.y < 0);
1516 keys = BITSET(keys, KEY_JUMP, PHYS_INPUT_BUTTON_JUMP(this));
1517 keys = BITSET(keys, KEY_CROUCH, PHYS_INPUT_BUTTON_CROUCH(this));
1518 keys = BITSET(keys, KEY_ATCK, PHYS_INPUT_BUTTON_ATCK(this));
1519 keys = BITSET(keys, KEY_ATCK2, PHYS_INPUT_BUTTON_ATCK2(this));
1520 this.pressedkeys = keys;
1524 ======================
1525 spectate mode routines
1526 ======================
1529 void SpectateCopy(entity this, entity spectatee)
1531 MUTATOR_CALLHOOK(SpectateCopy, spectatee, this);
1532 PS(this) = PS(spectatee);
1533 this.armortype = spectatee.armortype;
1534 this.armorvalue = spectatee.armorvalue;
1535 this.ammo_cells = spectatee.ammo_cells;
1536 this.ammo_plasma = spectatee.ammo_plasma;
1537 this.ammo_shells = spectatee.ammo_shells;
1538 this.ammo_nails = spectatee.ammo_nails;
1539 this.ammo_rockets = spectatee.ammo_rockets;
1540 this.ammo_fuel = spectatee.ammo_fuel;
1541 this.clip_load = spectatee.clip_load;
1542 this.clip_size = spectatee.clip_size;
1543 this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1544 this.health = spectatee.health;
1546 this.items = spectatee.items;
1547 this.last_pickup = spectatee.last_pickup;
1548 this.hit_time = spectatee.hit_time;
1549 this.strength_finished = spectatee.strength_finished;
1550 this.invincible_finished = spectatee.invincible_finished;
1551 this.pressedkeys = spectatee.pressedkeys;
1552 this.weapons = spectatee.weapons;
1553 this.vortex_charge = spectatee.vortex_charge;
1554 this.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
1555 this.hagar_load = spectatee.hagar_load;
1556 this.arc_heat_percent = spectatee.arc_heat_percent;
1557 this.minelayer_mines = spectatee.minelayer_mines;
1558 this.punchangle = spectatee.punchangle;
1559 this.view_ofs = spectatee.view_ofs;
1560 this.velocity = spectatee.velocity;
1561 this.dmg_take = spectatee.dmg_take;
1562 this.dmg_save = spectatee.dmg_save;
1563 this.dmg_inflictor = spectatee.dmg_inflictor;
1564 this.v_angle = spectatee.v_angle;
1565 this.angles = spectatee.v_angle;
1566 STAT(FROZEN, this) = STAT(FROZEN, spectatee);
1567 this.revive_progress = spectatee.revive_progress;
1568 if(!PHYS_INPUT_BUTTON_USE(this))
1569 this.fixangle = true;
1570 setorigin(this, spectatee.origin);
1571 setsize(this, spectatee.mins, spectatee.maxs);
1572 SetZoomState(spectatee.zoomstate);
1574 anticheat_spectatecopy(spectatee);
1575 this.hud = spectatee.hud;
1576 if(spectatee.vehicle)
1578 this.fixangle = false;
1579 //this.velocity = spectatee.vehicle.velocity;
1580 this.vehicle_health = spectatee.vehicle_health;
1581 this.vehicle_shield = spectatee.vehicle_shield;
1582 this.vehicle_energy = spectatee.vehicle_energy;
1583 this.vehicle_ammo1 = spectatee.vehicle_ammo1;
1584 this.vehicle_ammo2 = spectatee.vehicle_ammo2;
1585 this.vehicle_reload1 = spectatee.vehicle_reload1;
1586 this.vehicle_reload2 = spectatee.vehicle_reload2;
1590 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1591 WriteAngle(MSG_ONE, spectatee.v_angle.x);
1592 WriteAngle(MSG_ONE, spectatee.v_angle.y);
1593 WriteAngle(MSG_ONE, spectatee.v_angle.z);
1595 //WriteByte (MSG_ONE, SVC_SETVIEW);
1596 // WriteEntity(MSG_ONE, this);
1597 //makevectors(spectatee.v_angle);
1598 //setorigin(this, spectatee.origin - v_forward * 400 + v_up * 300);*/
1602 bool SpectateUpdate()
1607 if(!IS_PLAYER(self.enemy) || self == self.enemy)
1609 SetSpectatee(self, NULL);
1613 SpectateCopy(this, this.enemy);
1620 if(!IS_PLAYER(self.enemy))
1624 WriteByte(MSG_ONE, SVC_SETVIEW);
1625 WriteEntity(MSG_ONE, self.enemy);
1626 self.movetype = MOVETYPE_NONE;
1627 accuracy_resend(self);
1629 if(!SpectateUpdate())
1630 PutObserverInServer();
1635 void SetSpectatee(entity player, entity spectatee)
1637 entity old_spectatee = player.enemy;
1639 player.enemy = spectatee;
1642 // these are required to fix the spectator bug with arc
1643 if(old_spectatee && old_spectatee.arc_beam) { old_spectatee.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1644 if(player.enemy && player.enemy.arc_beam) { player.enemy.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1647 bool Spectate(entity pl)
1649 if(MUTATOR_CALLHOOK(SpectateSet, self, pl))
1653 SetSpectatee(self, pl);
1654 return SpectateSet();
1659 other = find(self.enemy, classname, STR_PLAYER);
1661 if (MUTATOR_CALLHOOK(SpectateNext, self, other))
1662 other = spec_player;
1664 other = find(other, classname, STR_PLAYER);
1666 if(other) { SetSpectatee(self, other); }
1668 return SpectateSet();
1673 // NOTE: chain order is from the highest to the lower entnum (unlike find)
1674 other = findchain(classname, STR_PLAYER);
1675 if (!other) // no player
1678 entity first = other;
1679 // skip players until current spectated player
1681 while(other && other != self.enemy)
1682 other = other.chain;
1684 switch (MUTATOR_CALLHOOK(SpectatePrev, self, other, first))
1686 case MUT_SPECPREV_FOUND:
1687 other = spec_player;
1689 case MUT_SPECPREV_RETURN:
1690 other = spec_player;
1692 case MUT_SPECPREV_CONTINUE:
1696 other = other.chain;
1703 SetSpectatee(self, other);
1704 return SpectateSet();
1709 ShowRespawnCountdown()
1711 Update a respawn countdown display.
1714 void ShowRespawnCountdown()
1717 if(!IS_DEAD(self)) // just respawned?
1721 number = ceil(self.respawn_time - time);
1724 if(number <= self.respawn_countdown)
1726 self.respawn_countdown = number - 1;
1727 if(ceil(self.respawn_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
1728 { Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(CNT_RESPAWN, number)); }
1733 void LeaveSpectatorMode()
1737 if(nJoinAllowed(self, self))
1739 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0)
1741 self.classname = STR_PLAYER;
1743 if(autocvar_g_campaign || autocvar_g_balance_teams)
1744 { JoinBestTeam(self, false, true); }
1746 if(autocvar_g_campaign)
1747 { campaign_bots_may_start = 1; }
1749 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_PREVENT_JOIN);
1751 PutClientInServer();
1753 if(IS_PLAYER(self)) { Send_Notification(NOTIF_ALL, world, MSG_INFO, ((teamplay && this.team != -1) ? APP_TEAM_ENT(this, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), self.netname); }
1756 stuffcmd(self, "menu_showteamselect\n");
1760 // Player may not join because g_maxplayers is set
1761 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_JOIN_PREVENT);
1766 * Determines whether the player is allowed to join. This depends on cvar
1767 * g_maxplayers, if it isn't used this function always return true, otherwise
1768 * it checks whether the number of currently playing players exceeds g_maxplayers.
1769 * @return int number of free slots for players, 0 if none
1771 bool nJoinAllowed(entity this, entity ignore)
1774 // this is called that way when checking if anyone may be able to join (to build qcstatus)
1775 // so report 0 free slots if restricted
1777 if(autocvar_g_forced_team_otherwise == "spectate")
1779 if(autocvar_g_forced_team_otherwise == "spectator")
1783 if(this.team_forced < 0)
1784 return false; // forced spectators can never join
1786 // TODO simplify this
1787 int totalClients = 0;
1788 int currentlyPlaying = 0;
1789 FOREACH_CLIENT(true, LAMBDA(
1792 if(IS_REAL_CLIENT(it))
1793 if(IS_PLAYER(it) || it.caplayer)
1797 if (!autocvar_g_maxplayers)
1798 return maxclients - totalClients;
1800 if(currentlyPlaying < autocvar_g_maxplayers)
1801 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
1807 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1808 * g_maxplayers_spectator_blocktime seconds
1810 void checkSpectatorBlock()
1812 if(IS_SPEC(self) || IS_OBSERVER(self))
1814 if(IS_REAL_CLIENT(self))
1816 if( time > (self.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
1817 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
1823 void PrintWelcomeMessage()
1825 if(self.motd_actived_time == 0)
1827 if (autocvar_g_campaign) {
1828 if ((IS_PLAYER(self) && PHYS_INPUT_BUTTON_INFO(self)) || (!IS_PLAYER(self))) {
1829 self.motd_actived_time = time;
1830 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, campaign_message);
1833 if (PHYS_INPUT_BUTTON_INFO(self)) {
1834 self.motd_actived_time = time;
1835 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1839 else if(self.motd_actived_time > 0) // showing MOTD or campaign message
1841 if (autocvar_g_campaign) {
1842 if (PHYS_INPUT_BUTTON_INFO(self))
1843 self.motd_actived_time = time;
1844 else if ((time - self.motd_actived_time > 2) && IS_PLAYER(self)) { // hide it some seconds after BUTTON_INFO has been released
1845 self.motd_actived_time = 0;
1846 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_MOTD);
1849 if (PHYS_INPUT_BUTTON_INFO(self))
1850 self.motd_actived_time = time;
1851 else if (time - self.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
1852 self.motd_actived_time = 0;
1853 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_MOTD);
1857 else //if(self.motd_actived_time < 0) // just connected, motd is active
1859 if(PHYS_INPUT_BUTTON_INFO(self)) // BUTTON_INFO hides initial MOTD
1860 self.motd_actived_time = -2; // wait until BUTTON_INFO gets released
1861 else if(self.motd_actived_time == -2 || IS_PLAYER(self) || IS_SPEC(self))
1863 // instanctly hide MOTD
1864 self.motd_actived_time = 0;
1865 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_MOTD);
1870 void ObserverThink()
1874 MinigameImpulse(self, self.impulse);
1877 float prefered_movetype;
1878 if (self.flags & FL_JUMPRELEASED) {
1879 if (PHYS_INPUT_BUTTON_JUMP(self) && !self.version_mismatch) {
1880 self.flags &= ~FL_JUMPRELEASED;
1881 self.flags |= FL_SPAWNING;
1882 } else if(PHYS_INPUT_BUTTON_ATCK(self) && !self.version_mismatch) {
1883 self.flags &= ~FL_JUMPRELEASED;
1884 if(SpectateNext()) {
1885 self.classname = STR_SPECTATOR;
1888 prefered_movetype = ((!PHYS_INPUT_BUTTON_USE(self) ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
1889 if (self.movetype != prefered_movetype)
1890 self.movetype = prefered_movetype;
1893 if (!(PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_JUMP(self))) {
1894 self.flags |= FL_JUMPRELEASED;
1895 if(self.flags & FL_SPAWNING)
1897 self.flags &= ~FL_SPAWNING;
1898 LeaveSpectatorMode();
1905 void SpectatorThink()
1909 if(MinigameImpulse(self, self.impulse))
1912 if (self.flags & FL_JUMPRELEASED) {
1913 if (PHYS_INPUT_BUTTON_JUMP(self) && !self.version_mismatch) {
1914 self.flags &= ~FL_JUMPRELEASED;
1915 self.flags |= FL_SPAWNING;
1916 } else if(PHYS_INPUT_BUTTON_ATCK(self) || self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209)) {
1917 self.flags &= ~FL_JUMPRELEASED;
1918 if(SpectateNext()) {
1919 self.classname = STR_SPECTATOR;
1921 self.classname = STR_OBSERVER;
1922 PutClientInServer();
1925 } else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229)) {
1926 self.flags &= ~FL_JUMPRELEASED;
1927 if(SpectatePrev()) {
1928 self.classname = STR_SPECTATOR;
1930 self.classname = STR_OBSERVER;
1931 PutClientInServer();
1934 } else if (PHYS_INPUT_BUTTON_ATCK2(self)) {
1935 self.flags &= ~FL_JUMPRELEASED;
1936 self.classname = STR_OBSERVER;
1937 PutClientInServer();
1939 if(!SpectateUpdate())
1940 PutObserverInServer();
1943 if (!(PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_ATCK2(self))) {
1944 self.flags |= FL_JUMPRELEASED;
1945 if(self.flags & FL_SPAWNING)
1947 self.flags &= ~FL_SPAWNING;
1948 LeaveSpectatorMode();
1952 if(!SpectateUpdate())
1953 PutObserverInServer();
1956 self.flags |= FL_CLIENT | FL_NOTARGET;
1959 void vehicles_enter (entity pl, entity veh);
1962 if (!IS_PLAYER(self))
1969 vehicles_exit(VHEF_NORMAL);
1973 else if(autocvar_g_vehicles_enter)
1975 if(!STAT(FROZEN, self))
1979 entity head, closest_target = world;
1980 head = WarpZone_FindRadius(self.origin, autocvar_g_vehicles_enter_radius, true);
1982 while(head) // find the closest acceptable target to enter
1984 if(head.vehicle_flags & VHF_ISVEHICLE)
1986 if(!head.owner || ((head.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(head.owner, self)))
1987 if(head.takedamage != DAMAGE_NO)
1991 if(vlen(self.origin - head.origin) < vlen(self.origin - closest_target.origin))
1992 { closest_target = head; }
1994 else { closest_target = head; }
2000 if(closest_target) { vehicles_enter(self, closest_target); return; }
2004 // a use key was pressed; call handlers
2005 MUTATOR_CALLHOOK(PlayerUseKey);
2013 Called every frame for each client before the physics are run
2016 .float usekeypressed;
2017 void() nexball_setstatus;
2018 .float last_vehiclecheck;
2020 void PlayerPreThink ()
2022 WarpZone_PlayerPhysics_FixVAngle();
2024 self.stat_game_starttime = game_starttime;
2025 self.stat_round_starttime = round_starttime;
2026 self.stat_allow_oldvortexbeam = autocvar_g_allow_oldvortexbeam;
2027 self.stat_leadlimit = autocvar_leadlimit;
2029 self.weaponsinmap = weaponsInMap;
2033 // physics frames: update anticheat stuff
2034 anticheat_prethink();
2037 if(blockSpectators && frametime)
2038 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2039 checkSpectatorBlock();
2043 // Savage: Check for nameless players
2044 if (isInvisibleString(self.netname)) {
2045 string new_name = strzone(strcat("Player@", ftos(self.playerid)));
2046 if(autocvar_sv_eventlog)
2047 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", new_name));
2048 if(self.netname_previous)
2049 strunzone(self.netname_previous);
2050 self.netname_previous = strzone(new_name);
2051 self.netname = self.netname_previous;
2052 // stuffcmd(self, strcat("name ", self.netname, "\n"));
2053 } else if(self.netname_previous != self.netname) {
2054 if(autocvar_sv_eventlog)
2055 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2056 if(self.netname_previous)
2057 strunzone(self.netname_previous);
2058 self.netname_previous = strzone(self.netname);
2062 if(self.version_nagtime)
2063 if(self.cvar_g_xonoticversion)
2064 if(time > self.version_nagtime)
2066 // don't notify git users
2067 if(strstr(self.cvar_g_xonoticversion, "git", 0) < 0 && strstr(self.cvar_g_xonoticversion, "autobuild", 0) < 0)
2069 if(strstr(autocvar_g_xonoticversion, "git", 0) >= 0 || strstr(autocvar_g_xonoticversion, "autobuild", 0) >= 0)
2071 // notify release users if connecting to git
2072 LOG_TRACE("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", autocvar_g_xonoticversion, " (beta)^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2073 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2078 r = vercmp(self.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2081 // give users new version
2082 LOG_TRACE("^1NOTE^7 to ", self.netname, "^7 - ^3Xonotic ", autocvar_g_xonoticversion, "^7 is out, and you still have ^3Xonotic ", self.cvar_g_xonoticversion, "^1 - get the update from ^4http://www.xonotic.org/^1!\n");
2083 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2087 // notify users about old server version
2088 LOG_INFO("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", autocvar_g_xonoticversion, "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2089 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2093 self.version_nagtime = 0;
2097 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2099 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_GODMODE_OFF, self.max_armorvalue);
2100 self.max_armorvalue = 0;
2103 if(STAT(FROZEN, self) == 2)
2105 self.revive_progress = bound(0, self.revive_progress + frametime * self.revive_speed, 1);
2106 self.health = max(1, self.revive_progress * start_health);
2107 self.iceblock.alpha = bound(0.2, 1 - self.revive_progress, 1);
2109 if(self.revive_progress >= 1)
2112 else if(STAT(FROZEN, self) == 3)
2114 self.revive_progress = bound(0, self.revive_progress - frametime * self.revive_speed, 1);
2115 self.health = max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * self.revive_progress );
2120 vehicles_exit(VHEF_RELEASE);
2121 self.event_damage(self, self, self.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, self.origin, '0 0 0');
2123 else if ( self.revive_progress <= 0 )
2127 MUTATOR_CALLHOOK(PlayerPreThink);
2129 if(autocvar_g_vehicles_enter)
2130 if(time > self.last_vehiclecheck)
2133 if(!STAT(FROZEN, self))
2138 for(veh = world; (veh = findflags(veh, vehicle_flags, VHF_ISVEHICLE)); )
2139 if(vlen(veh.origin - self.origin) < autocvar_g_vehicles_enter_radius)
2141 if(veh.takedamage != DAMAGE_NO)
2142 if((veh.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(veh.owner, self))
2143 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
2145 if(!veh.team || SAME_TEAM(self, veh))
2146 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER);
2147 else if(autocvar_g_vehicles_steal)
2148 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
2150 self.last_vehiclecheck = time + 1;
2153 if(!self.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2155 if(PHYS_INPUT_BUTTON_USE(self) && !self.usekeypressed)
2157 self.usekeypressed = PHYS_INPUT_BUTTON_USE(self);
2160 if(IS_REAL_CLIENT(self))
2161 PrintWelcomeMessage();
2166 CheckRules_Player();
2168 if (intermission_running)
2170 IntermissionThink (); // otherwise a button could be missed between
2171 return; // the think tics
2174 //don't allow the player to turn around while game is paused!
2175 if(timeout_status == TIMEOUT_ACTIVE) {
2176 // FIXME turn this into CSQC stuff
2177 self.v_angle = self.lastV_angle;
2178 self.angles = self.lastV_angle;
2179 self.fixangle = true;
2189 if(self.personal && g_race_qualifying)
2191 if(time > self.respawn_time)
2193 self.respawn_time = time + 1; // only retry once a second
2194 self.stat_respawn_time = self.respawn_time;
2201 float button_pressed;
2204 button_pressed = (PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_ATCK2(self) || PHYS_INPUT_BUTTON_HOOK(self) || PHYS_INPUT_BUTTON_USE(self));
2206 if (self.deadflag == DEAD_DYING)
2208 if((self.respawn_flags & RESPAWN_FORCE) && !autocvar_g_respawn_delay_max)
2209 self.deadflag = DEAD_RESPAWNING;
2210 else if(!button_pressed)
2211 self.deadflag = DEAD_DEAD;
2213 else if (self.deadflag == DEAD_DEAD)
2216 self.deadflag = DEAD_RESPAWNABLE;
2217 else if(time >= self.respawn_time_max && (self.respawn_flags & RESPAWN_FORCE))
2218 self.deadflag = DEAD_RESPAWNING;
2220 else if (self.deadflag == DEAD_RESPAWNABLE)
2223 self.deadflag = DEAD_RESPAWNING;
2225 else if (self.deadflag == DEAD_RESPAWNING)
2227 if(time > self.respawn_time)
2229 self.respawn_time = time + 1; // only retry once a second
2230 self.respawn_time_max = self.respawn_time;
2235 ShowRespawnCountdown();
2237 if(self.respawn_flags & RESPAWN_SILENT)
2238 self.stat_respawn_time = 0;
2239 else if((self.respawn_flags & RESPAWN_FORCE) && autocvar_g_respawn_delay_max)
2240 self.stat_respawn_time = self.respawn_time_max;
2242 self.stat_respawn_time = self.respawn_time;
2245 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2246 if(self.deadflag == DEAD_RESPAWNING && self.stat_respawn_time > 0)
2247 self.stat_respawn_time *= -1;
2252 self.prevorigin = self.origin;
2254 float do_crouch = PHYS_INPUT_BUTTON_CROUCH(self);
2259 if(STAT(FROZEN, self))
2262 // WEAPONTODO: THIS SHIT NEEDS TO GO EVENTUALLY
2263 // It cannot be predicted by the engine!
2264 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
2265 if((PS(self).m_weapon == WEP_SHOCKWAVE || PS(self).m_weapon == WEP_SHOTGUN) && self.(weaponentity).wframe == WFRAME_FIRE2 && time < self.(weaponentity).weapon_nextthink)
2273 self.view_ofs = STAT(PL_CROUCH_VIEW_OFS, self);
2274 setsize (self, STAT(PL_CROUCH_MIN, self), STAT(PL_CROUCH_MAX, self));
2275 // setanim(self, self.anim_duck, false, true, true); // this anim is BROKEN anyway
2282 tracebox(self.origin, STAT(PL_MIN, self), STAT(PL_MAX, self), self.origin, false, self);
2283 if (!trace_startsolid)
2285 self.crouch = false;
2286 self.view_ofs = STAT(PL_VIEW_OFS, self);
2287 setsize (self, STAT(PL_MIN, self), STAT(PL_MAX, self));
2292 FixPlayermodel(self);
2294 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2297 self.items &= ~self.items_added;
2299 W_WeaponFrame(self);
2301 self.items_added = 0;
2302 if(self.items & ITEM_Jetpack.m_itemid)
2303 if(self.items & ITEM_JetpackRegen.m_itemid || self.ammo_fuel >= 0.01)
2304 self.items_added |= IT_FUEL;
2306 self.items |= self.items_added;
2311 // WEAPONTODO: Add a weapon request for this
2312 // rot vortex charge to the charge limit
2313 if(WEP_CVAR(vortex, charge_rot_rate) && self.vortex_charge > WEP_CVAR(vortex, charge_limit) && self.vortex_charge_rottime < time)
2314 self.vortex_charge = bound(WEP_CVAR(vortex, charge_limit), self.vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1);
2320 secrets_setstatus();
2323 monsters_setstatus(self);
2325 self.dmg_team = max(0, self.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2327 //self.angles_y=self.v_angle_y + 90; // temp
2328 } else if(gameover) {
2329 if (intermission_running)
2330 IntermissionThink (); // otherwise a button could be missed between
2332 } else if(IS_OBSERVER(self)) {
2334 } else if(IS_SPEC(self)) {
2338 // WEAPONTODO: Add weapon request for this
2341 PHYS_INPUT_BUTTON_ZOOM(self)
2342 || PHYS_INPUT_BUTTON_ZOOMSCRIPT(self)
2343 || (PHYS_INPUT_BUTTON_ATCK2(self) && PS(self).m_weapon == WEP_VORTEX)
2344 || (PHYS_INPUT_BUTTON_ATCK2(self) && PS(self).m_weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0)
2347 float oldspectatee_status;
2348 oldspectatee_status = self.spectatee_status;
2350 self.spectatee_status = etof(self.enemy);
2351 else if(IS_OBSERVER(self))
2352 self.spectatee_status = etof(self);
2354 self.spectatee_status = 0;
2355 if(self.spectatee_status != oldspectatee_status)
2357 ClientData_Touch(self);
2359 race_InitSpectator();
2362 if(self.teamkill_soundtime)
2363 if(time > self.teamkill_soundtime)
2365 self.teamkill_soundtime = 0;
2367 entity e = self.teamkill_soundsource;
2368 entity oldpusher = e.pusher;
2370 PlayerSound(e, playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2371 e.pusher = oldpusher;
2374 if(self.taunt_soundtime)
2375 if(time > self.taunt_soundtime)
2377 self.taunt_soundtime = 0;
2378 PlayerSound(self, playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2381 target_voicescript_next(self);
2383 // WEAPONTODO: Move into weaponsystem somehow
2384 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2385 if (PS(self).m_weapon == WEP_Null)
2386 self.clip_load = self.clip_size = 0;
2389 void DrownPlayer(entity this)
2394 if (this.waterlevel != WATERLEVEL_SUBMERGED)
2396 if(this.air_finished < time)
2397 PlayerSound(this, playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
2398 this.air_finished = time + autocvar_g_balance_contents_drowndelay;
2401 else if (this.air_finished < time)
2403 if (this.pain_finished < time)
2405 Damage (this, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, this.origin, '0 0 0');
2406 this.pain_finished = time + 0.5;
2415 Called every frame for each client after the physics are run
2418 .float idlekick_lasttimeleft;
2419 void PlayerPostThink ()
2421 if(sv_maxidle > 0 && frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2422 if(IS_REAL_CLIENT(self))
2423 if(IS_PLAYER(self) || sv_maxidle_spectatorsareidle)
2425 if (time - self.parm_idlesince < 1) // instead of (time == self.parm_idlesince) to support sv_maxidle <= 10
2427 if(self.idlekick_lasttimeleft)
2429 self.idlekick_lasttimeleft = 0;
2430 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CPID_IDLING);
2436 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2437 if(timeleft == min(10, sv_maxidle - 1)) // - 1 to support sv_maxidle <= 10
2439 if(!self.idlekick_lasttimeleft)
2440 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
2444 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_KICK_IDLING, self.netname);
2448 else if(timeleft <= 10)
2450 if(timeleft != self.idlekick_lasttimeleft)
2451 { Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(CNT_IDLE, timeleft)); }
2452 self.idlekick_lasttimeleft = timeleft;
2459 //CheckPlayerJump();
2461 if(IS_PLAYER(self)) {
2463 CheckRules_Player();
2466 ImpulseCommands(self);
2467 if (intermission_running)
2468 return; // intermission or finale
2474 for(i = 0; i < 1000; ++i)
2477 end = self.origin + '0 0 1024' + 512 * randomvec();
2478 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2479 if(trace_fraction < 1)
2480 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2482 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2488 if(self.waypointsprite_attachedforcarrier)
2489 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id));
2493 CSQCMODEL_AUTOUPDATE(self);