1 #include "waypointsprites.qh"
3 #include "cl_impulse.qh"
4 #include "cl_player.qh"
8 #include "miscfunctions.qh"
10 #include "teamplay.qh"
11 #include "playerdemo.qh"
15 #include "bot/navigation.qh"
17 #include "weapons/hitplot.qh"
18 #include "weapons/weaponsystem.qh"
20 #include "../common/net_notice.qh"
22 #include "../common/monsters/sv_monsters.qh"
24 #include "../warpzonelib/server.qh"
28 void send_CSQC_teamnagger() {
29 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
30 WriteByte(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
33 int CountSpectators(entity player, entity to)
35 if(!player) { return 0; } // not sure how, but best to be safe
39 FOR_EACH_REALCLIENT(head)
43 if(head.enemy == player)
50 void WriteSpectators(entity player, entity to)
52 if(!player) { return; } // not sure how, but best to be safe
55 FOR_EACH_REALCLIENT(head)
59 if(head.enemy == player)
60 WriteByte(MSG_ENTITY, num_for_edict(head));
64 bool ClientData_Send(entity to, int sf)
81 sf |= 1; // forced scoreboard
82 if(to.spectatee_status)
83 sf |= 2; // spectator ent number follows
86 if(e.porto_v_angle_held)
87 sf |= 8; // angles held
88 // always check spectators
89 sf |= 16; // spectator handling?
91 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
92 WriteByte(MSG_ENTITY, sf);
95 WriteByte(MSG_ENTITY, to.spectatee_status);
99 WriteAngle(MSG_ENTITY, e.v_angle.x);
100 WriteAngle(MSG_ENTITY, e.v_angle.y);
105 float specs = CountSpectators(e, to);
106 WriteByte(MSG_ENTITY, specs);
107 WriteSpectators(e, to);
113 void ClientData_Attach()
115 Net_LinkEntity(self.clientdata = spawn(), false, 0, ClientData_Send);
116 self.clientdata.drawonlytoclient = self;
117 self.clientdata.owner = self;
120 void ClientData_Detach()
122 remove(self.clientdata);
123 self.clientdata = world;
126 void ClientData_Touch(entity e)
128 e.clientdata.SendFlags = 1;
130 // make it spectatable
132 FOR_EACH_REALCLIENT(e2)
137 e2.clientdata.SendFlags = 1;
141 .string netname_previous;
143 void SetSpectator(entity player, entity spectatee);
150 Checks if the argument string can be a valid playermodel.
151 Returns a valid one in doubt.
154 string FallbackPlayerModel;
155 string CheckPlayerModel(string plyermodel) {
156 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
158 // note: we cannot summon Don Strunzone here, some player may
159 // still have the model string set. In case anyone manages how
160 // to change a cvar default, we'll have a small leak here.
161 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
163 // only in right path
164 if( substring(plyermodel,0,14) != "models/player/")
165 return FallbackPlayerModel;
166 // only good file extensions
167 if(substring(plyermodel,-4,4) != ".zym")
168 if(substring(plyermodel,-4,4) != ".dpm")
169 if(substring(plyermodel,-4,4) != ".iqm")
170 if(substring(plyermodel,-4,4) != ".md3")
171 if(substring(plyermodel,-4,4) != ".psk")
172 return FallbackPlayerModel;
173 // forbid the LOD models
174 if(substring(plyermodel, -9,5) == "_lod1")
175 return FallbackPlayerModel;
176 if(substring(plyermodel, -9,5) == "_lod2")
177 return FallbackPlayerModel;
178 if(plyermodel != strtolower(plyermodel))
179 return FallbackPlayerModel;
180 // also, restrict to server models
181 if(autocvar_sv_servermodelsonly)
183 if(!fexists(plyermodel))
184 return FallbackPlayerModel;
189 void setplayermodel(entity e, string modelname)
191 precache_model(modelname);
192 setmodel(e, modelname);
193 player_setupanimsformodel();
194 UpdatePlayerSounds();
201 putting a client as observer in the server
204 void FixPlayermodel();
205 void PutObserverInServer (void)
209 SetSpectator(self, world);
211 self.hud = HUD_NORMAL;
213 if(IS_PLAYER(self)) { pointparticles(particleeffectnum("spawn_event_neutral"), self.origin, '0 0 0', 1); }
215 spot = SelectSpawnPoint (true);
217 error("No spawnpoints for observers?!?\n");
218 RemoveGrapplingHook(self); // Wazat's Grappling Hook
220 if(IS_REAL_CLIENT(self))
223 WriteByte(MSG_ONE, SVC_SETVIEW);
224 WriteEntity(MSG_ONE, self);
227 self.frags = FRAGS_SPECTATOR;
229 MUTATOR_CALLHOOK(MakePlayerObserver);
231 Portal_ClearAll(self);
238 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
243 vehicles_exit(VHEF_RELESE);
245 WaypointSprite_PlayerDead();
247 if (!g_ca) // don't reset teams when moving a ca player to the spectators
248 self.team = -1; // move this as it is needed to log the player spectating in eventlog
250 if(self.killcount != -666)
252 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_SPECTATE, self.netname);
253 if(autocvar_g_chat_nospectators == 1 || (cvar("g_warmup") && !(warmup_stage || gameover) && autocvar_g_chat_nospectators == 2))
254 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_CHAT_NOSPECTATORS);
256 if(self.just_joined == false) {
257 LogTeamchange(self.playerid, -1, 4);
259 self.just_joined = false;
262 PlayerScore_Clear(self); // clear scores when needed
264 accuracy_resend(self);
266 self.spectatortime = time;
268 self.classname = "observer";
269 self.iscreature = false;
270 self.teleportable = TELEPORT_SIMPLE;
271 self.damagedbycontents = false;
273 self.takedamage = DAMAGE_NO;
274 self.solid = SOLID_NOT;
275 self.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink
276 self.flags = FL_CLIENT | FL_NOTARGET;
277 self.armorvalue = 666;
279 self.armorvalue = autocvar_g_balance_armor_start;
280 self.pauserotarmor_finished = 0;
281 self.pauserothealth_finished = 0;
282 self.pauseregen_finished = 0;
283 self.damageforcescale = 0;
285 self.respawn_flags = 0;
286 self.respawn_time = 0;
287 self.stat_respawn_time = 0;
292 self.pain_finished = 0;
293 self.strength_finished = 0;
294 self.invincible_finished = 0;
295 self.superweapons_finished = 0;
298 self.think = func_null;
301 self.deadflag = DEAD_NO;
302 self.angles = spot.angles;
304 self.fixangle = true;
306 self.revival_time = 0;
308 setorigin (self, (spot.origin + PL_VIEW_OFS)); // offset it so that the spectator spawns higher off the ground, looks better this way
309 self.prevorigin = self.origin;
311 self.weapons = '0 0 0';
314 setmodel(self, "null");
315 self.drawonlytoclient = self;
317 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
318 self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
321 self.weaponname = "";
322 self.switchingweapon = 0;
323 self.weaponmodel = "";
324 self.weaponentity = world;
325 self.exteriorweaponentity = world;
326 self.killcount = -666;
327 self.velocity = '0 0 0';
328 self.avelocity = '0 0 0';
329 self.punchangle = '0 0 0';
330 self.punchvector = '0 0 0';
331 self.oldvelocity = self.velocity;
332 self.fire_endtime = -1;
333 self.event_damage = func_null;
336 .float model_randomizer;
337 void FixPlayermodel()
340 float defaultskin, chmdl, oldskin, n, i;
347 if(autocvar_sv_defaultcharacter == 1)
352 s = Static_Team_ColorName_Lower(self.team);
355 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
356 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
360 if(defaultmodel == "")
362 defaultmodel = autocvar_sv_defaultplayermodel;
363 defaultskin = autocvar_sv_defaultplayerskin;
366 n = tokenize_console(defaultmodel);
369 defaultmodel = argv(floor(n * self.model_randomizer));
370 // However, do NOT randomize if the player-selected model is in the list.
371 for (i = 0; i < n; ++i)
372 if ((argv(i) == self.playermodel && defaultskin == stof(self.playerskin)) || argv(i) == strcat(self.playermodel, ":", self.playerskin))
373 defaultmodel = argv(i);
376 i = strstrofs(defaultmodel, ":", 0);
379 defaultskin = stof(substring(defaultmodel, i+1, -1));
380 defaultmodel = substring(defaultmodel, 0, i);
384 if(defaultmodel != "")
386 if (defaultmodel != self.model)
390 setplayermodel (self, defaultmodel);
391 setsize (self, m1, m2);
396 self.skin = defaultskin;
398 if (self.playermodel != self.model || self.playermodel == "")
400 self.playermodel = CheckPlayerModel(self.playermodel); // this is never "", so no endless loop
403 setplayermodel (self, self.playermodel);
404 setsize (self, m1, m2);
409 self.skin = stof(self.playerskin);
412 if(chmdl || oldskin != self.skin) // model or skin has changed
414 self.species = player_getspecies(); // update species
415 UpdatePlayerSounds(); // update skin sounds
419 if(strlen(autocvar_sv_defaultplayercolors))
420 if(self.clientcolors != stof(autocvar_sv_defaultplayercolors))
421 setcolor(self, stof(autocvar_sv_defaultplayercolors));
428 Called when a client spawns in the server
431 void PutClientInServer (void)
433 if(IS_BOT_CLIENT(self))
434 self.classname = "player";
435 else if(IS_REAL_CLIENT(self))
438 WriteByte(MSG_ONE, SVC_SETVIEW);
439 WriteEntity(MSG_ONE, self);
442 SetSpectator(self, world);
447 MUTATOR_CALLHOOK(PutClientInServer);
450 self.classname = "observer";
454 entity spot, oldself;
457 accuracy_resend(self);
460 JoinBestTeam(self, false, true);
462 spot = SelectSpawnPoint (false);
465 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
466 return; // spawn failed
469 RemoveGrapplingHook(self); // Wazat's Grappling Hook
472 vehicles_exit(VHEF_RELESE);
474 self.classname = "player";
475 self.wasplayer = true;
476 self.iscreature = true;
477 self.teleportable = TELEPORT_NORMAL;
478 self.damagedbycontents = true;
479 self.movetype = MOVETYPE_WALK;
480 self.solid = SOLID_SLIDEBOX;
481 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
482 if(autocvar_g_playerclip_collisions)
483 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
484 if(IS_BOT_CLIENT(self) && autocvar_g_botclip_collisions)
485 self.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
486 self.frags = FRAGS_PLAYER;
487 if(INDEPENDENT_PLAYERS)
488 MAKE_INDEPENDENT_PLAYER(self);
489 self.flags = FL_CLIENT;
490 if(autocvar__notarget)
491 self.flags |= FL_NOTARGET;
492 self.takedamage = DAMAGE_AIM;
494 self.effects |= EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
495 self.air_finished = time + 12;
497 if(WEP_CVAR(vortex, charge))
499 if(WEP_CVAR_SEC(vortex, chargepool))
500 self.vortex_chargepool_ammo = 1;
501 self.vortex_charge = WEP_CVAR(vortex, charge_start);
506 self.ammo_shells = warmup_start_ammo_shells;
507 self.ammo_nails = warmup_start_ammo_nails;
508 self.ammo_rockets = warmup_start_ammo_rockets;
509 self.ammo_cells = warmup_start_ammo_cells;
510 self.ammo_plasma = warmup_start_ammo_plasma;
511 self.ammo_fuel = warmup_start_ammo_fuel;
512 self.health = warmup_start_health;
513 self.armorvalue = warmup_start_armorvalue;
514 self.weapons = WARMUP_START_WEAPONS;
518 self.ammo_shells = start_ammo_shells;
519 self.ammo_nails = start_ammo_nails;
520 self.ammo_rockets = start_ammo_rockets;
521 self.ammo_cells = start_ammo_cells;
522 self.ammo_plasma = start_ammo_plasma;
523 self.ammo_fuel = start_ammo_fuel;
524 self.health = start_health;
525 self.armorvalue = start_armorvalue;
526 self.weapons = start_weapons;
529 if(self.weapons & WEPSET_SUPERWEAPONS)
530 self.superweapons_finished = time + autocvar_g_balance_superweapons_time;
532 self.superweapons_finished = 0;
534 if(g_weaponarena_random) // WEAPONTODO: more stuff that should be in a mutator. also: rename those cvars
536 if(g_weaponarena_random_with_blaster)
537 self.weapons &= ~WEPSET_BLASTER;
538 W_RandomWeapons(self, g_weaponarena_random);
539 if(g_weaponarena_random_with_blaster)
540 self.weapons |= WEPSET_BLASTER;
543 self.items = start_items;
545 self.spawnshieldtime = time + autocvar_g_spawnshieldtime;
546 self.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
547 self.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
548 self.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
549 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
550 //extend the pause of rotting if client was reset at the beginning of the countdown
551 if(!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
552 self.spawnshieldtime += game_starttime - time;
553 self.pauserotarmor_finished += game_starttime - time;
554 self.pauserothealth_finished += game_starttime - time;
555 self.pauseregen_finished += game_starttime - time;
557 self.damageforcescale = 2;
559 self.respawn_flags = 0;
560 self.respawn_time = 0;
561 self.stat_respawn_time = 0;
565 self.pain_finished = 0;
566 self.strength_finished = 0;
567 self.invincible_finished = 0;
569 // players have no think function
570 self.think = func_null;
574 self.ballistics_density = autocvar_g_ballistics_density_player;
578 self.deadflag = DEAD_NO;
580 self.angles = spot.angles;
582 self.angles_z = 0; // never spawn tilted even if the spot says to
583 if(IS_BOT_CLIENT(self))
584 self.v_angle = self.angles;
585 self.fixangle = true; // turn this way immediately
586 self.velocity = '0 0 0';
587 self.avelocity = '0 0 0';
588 self.punchangle = '0 0 0';
589 self.punchvector = '0 0 0';
590 self.oldvelocity = self.velocity;
591 self.fire_endtime = -1;
592 self.revival_time = 0;
594 entity spawnevent = spawn();
595 spawnevent.owner = self;
596 Net_LinkEntity(spawnevent, false, 0.5, SpawnEvent_Send);
598 // Cut off any still running player sounds.
599 stopsound(self, CH_PLAYER_SINGLE);
603 self.drawonlytoclient = world;
606 self.view_ofs = PL_VIEW_OFS;
607 setsize (self, PL_MIN, PL_MAX);
608 self.spawnorigin = spot.origin;
609 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins.z - 24));
610 // don't reset back to last position, even if new position is stuck in solid
611 self.oldorigin = self.origin;
612 self.prevorigin = self.origin;
613 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
614 self.lastteleporttime = time; // prevent insane speeds due to changing origin
615 self.hud = HUD_NORMAL;
617 self.event_damage = PlayerDamage;
619 self.bot_attack = true;
620 self.monster_attack = true;
622 self.spider_slowness = 0;
624 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
626 if(self.killcount == -666) {
627 PlayerScore_Clear(self);
631 CL_SpawnWeaponentity();
632 self.alpha = default_player_alpha;
633 self.colormod = '1 1 1' * autocvar_g_player_brightness;
634 self.exteriorweaponentity.alpha = default_weapon_alpha;
636 self.speedrunning = false;
638 //stuffcmd(self, "chase_active 0");
639 //stuffcmd(self, "set viewsize $tmpviewsize \n");
641 target_voicescript_clear(self);
643 // reset fields the weapons may use
644 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
646 WEP_ACTION(j, WR_RESETPLAYER);
648 // all weapons must be fully loaded when we spawn
649 entity e = get_weaponinfo(j);
650 if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
651 self.(weapon_load[j]) = e.reloading_ammo;
659 self.target = string_null;
668 MUTATOR_CALLHOOK(PlayerSpawn);
670 if(autocvar_spawn_debug)
672 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
673 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
676 self.switchweapon = w_getbestweapon(self);
677 self.cnt = -1; // W_LastWeapon will not complain
679 self.weaponname = "";
680 self.switchingweapon = 0;
684 self.alivetime = time;
688 else if(IS_OBSERVER(self))
690 PutObserverInServer ();
694 .float ebouncefactor, ebouncestop; // electro's values
695 // TODO do we need all these fields, or should we stop autodetecting runtime
696 // changes and just have a console command to update this?
697 float ClientInit_SendEntity(entity to, float sf)
699 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
700 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
701 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[0]));
702 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[1]));
703 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[2]));
704 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[3]));
705 WriteInt24_t(MSG_ENTITY, compressShotOrigin(arc_shotorigin[0]));
706 WriteInt24_t(MSG_ENTITY, compressShotOrigin(arc_shotorigin[1]));
707 WriteInt24_t(MSG_ENTITY, compressShotOrigin(arc_shotorigin[2]));
708 WriteInt24_t(MSG_ENTITY, compressShotOrigin(arc_shotorigin[3]));
710 if(sv_foginterval && world.fog != "")
711 WriteString(MSG_ENTITY, world.fog);
713 WriteString(MSG_ENTITY, "");
714 WriteByte(MSG_ENTITY, self.count * 255.0); // g_balance_armor_blockpercent
715 WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_mortar_bouncefactor // WEAPONTODO
716 WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_mortar_bouncestop
717 WriteCoord(MSG_ENTITY, self.ebouncefactor); // g_balance_mortar_bouncefactor
718 WriteCoord(MSG_ENTITY, self.ebouncestop); // g_balance_mortar_bouncestop
719 WriteByte(MSG_ENTITY, WEP_CVAR(vortex, secondary)); // client has to know if it should zoom or not // WEAPONTODO
720 WriteByte(MSG_ENTITY, WEP_CVAR(rifle, secondary)); // client has to know if it should zoom or not // WEAPONTODO
721 WriteByte(MSG_ENTITY, serverflags); // client has to know if it should zoom or not
722 WriteByte(MSG_ENTITY, WEP_CVAR(minelayer, limit)); // minelayer max mines // WEAPONTODO
723 WriteByte(MSG_ENTITY, WEP_CVAR_SEC(hagar, load_max)); // hagar max loadable rockets // WEAPONTODO
724 WriteCoord(MSG_ENTITY, autocvar_g_trueaim_minrange);
725 WriteByte(MSG_ENTITY, WEP_CVAR(porto, secondary)); // WEAPONTODO
729 void ClientInit_CheckUpdate()
731 self.nextthink = time;
732 if(self.count != autocvar_g_balance_armor_blockpercent)
734 self.count = autocvar_g_balance_armor_blockpercent;
737 if(self.bouncefactor != autocvar_g_balance_mortar_bouncefactor) // WEAPONTODO
739 self.bouncefactor = autocvar_g_balance_mortar_bouncefactor;
742 if(self.bouncestop != autocvar_g_balance_mortar_bouncestop)
744 self.bouncestop = autocvar_g_balance_mortar_bouncestop;
747 if(self.ebouncefactor != autocvar_g_balance_electro_secondary_bouncefactor)
749 self.ebouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
752 if(self.ebouncestop != autocvar_g_balance_electro_secondary_bouncestop)
754 self.ebouncestop = autocvar_g_balance_electro_secondary_bouncestop;
759 void ClientInit_Spawn()
764 e.classname = "clientinit";
765 e.think = ClientInit_CheckUpdate;
766 Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
770 ClientInit_CheckUpdate();
779 void SetNewParms (void)
781 // initialize parms for a new player
782 parm1 = -(86400 * 366);
790 void SetChangeParms (void)
792 // save parms for level change
793 parm1 = self.parm_idlesince - time;
801 void DecodeLevelParms (void)
804 self.parm_idlesince = parm1;
805 if(self.parm_idlesince == -(86400 * 366))
806 self.parm_idlesince = time;
808 // whatever happens, allow 60 seconds of idling directly after connect for map loading
809 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
816 Called when a client types 'kill' in the console
820 .float clientkill_nexttime;
821 void ClientKill_Now_TeamChange()
823 if(self.killindicator_teamchange == -1)
825 JoinBestTeam( self, false, true );
827 else if(self.killindicator_teamchange == -2)
830 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
831 PutObserverInServer();
834 SV_ChangeTeam(self.killindicator_teamchange - 1);
835 self.killindicator_teamchange = 0;
838 void ClientKill_Now()
842 vehicles_exit(VHEF_RELESE);
843 if(!self.killindicator_teamchange)
845 self.vehicle_health = -1;
846 Damage(self, self, self, 1 , DEATH_KILL, self.origin, '0 0 0');
850 if(self.killindicator && !wasfreed(self.killindicator))
851 remove(self.killindicator);
853 self.killindicator = world;
855 if(self.killindicator_teamchange)
856 ClientKill_Now_TeamChange();
859 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
861 // now I am sure the player IS dead
863 void KillIndicator_Think()
867 self.owner.killindicator = world;
872 if (self.owner.alpha < 0 && !self.owner.vehicle)
874 self.owner.killindicator = world;
882 ClientKill_Now(); // no oldself needed
885 else if(g_cts && self.health == 1) // health == 1 means that it's silent
887 self.nextthink = time + 1;
893 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
894 if(IS_REAL_CLIENT(self.owner))
897 { Send_Notification(NOTIF_ONE, self.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, self.cnt)); }
899 self.nextthink = time + 1;
904 float clientkilltime;
905 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
914 killtime = autocvar_g_balance_kill_delay;
916 if(g_race_qualifying || g_cts)
919 if(g_cts && self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
921 remove(self.killindicator);
922 self.killindicator = world;
924 ClientKill_Now(); // allow instant kill in this case
928 self.killindicator_teamchange = targetteam;
930 if(!self.killindicator)
932 if(self.deadflag == DEAD_NO)
934 killtime = max(killtime, self.clientkill_nexttime - time);
935 self.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
938 if(killtime <= 0 || !IS_PLAYER(self) || self.deadflag != DEAD_NO)
944 starttime = max(time, clientkilltime);
946 self.killindicator = spawn();
947 self.killindicator.owner = self;
948 self.killindicator.scale = 0.5;
949 setattachment(self.killindicator, self, "");
950 setorigin(self.killindicator, '0 0 52');
951 self.killindicator.think = KillIndicator_Think;
952 self.killindicator.nextthink = starttime + (self.lip) * 0.05;
953 clientkilltime = max(clientkilltime, self.killindicator.nextthink + 0.05);
954 self.killindicator.cnt = ceil(killtime);
955 self.killindicator.count = bound(0, ceil(killtime), 10);
956 //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
958 for(e = world; (e = find(e, classname, "body")) != world; )
962 e.killindicator = spawn();
963 e.killindicator.owner = e;
964 e.killindicator.scale = 0.5;
965 setattachment(e.killindicator, e, "");
966 setorigin(e.killindicator, '0 0 52');
967 e.killindicator.think = KillIndicator_Think;
968 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
969 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
970 e.killindicator.cnt = ceil(killtime);
975 if(self.killindicator)
977 if(targetteam == 0) // just die
979 self.killindicator.colormod = '0 0 0';
980 if(IS_REAL_CLIENT(self))
981 if(self.killindicator.cnt > 0)
982 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, self.killindicator.cnt);
984 else if(targetteam == -1) // auto
986 self.killindicator.colormod = '0 1 0';
987 if(IS_REAL_CLIENT(self))
988 if(self.killindicator.cnt > 0)
989 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, self.killindicator.cnt);
991 else if(targetteam == -2) // spectate
993 self.killindicator.colormod = '0.5 0.5 0.5';
994 if(IS_REAL_CLIENT(self))
995 if(self.killindicator.cnt > 0)
996 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, self.killindicator.cnt);
1000 self.killindicator.colormod = Team_ColorRGB(targetteam);
1001 if(IS_REAL_CLIENT(self))
1002 if(self.killindicator.cnt > 0)
1003 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, APP_TEAM_NUM_4(targetteam, CENTER_TEAMCHANGE_), self.killindicator.cnt);
1009 void ClientKill (void)
1011 if(gameover) return;
1012 if(self.player_blocked) return;
1013 if(self.frozen) return;
1015 ClientKill_TeamChange(0);
1018 void CTS_ClientKill (entity e) // silent version of ClientKill, used when player finishes a CTS run. Useful to prevent cheating by running back to the start line and starting out with more speed
1020 e.killindicator = spawn();
1021 e.killindicator.owner = e;
1022 e.killindicator.think = KillIndicator_Think;
1023 e.killindicator.nextthink = time + (e.lip) * 0.05;
1024 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
1025 e.killindicator.health = 1; // this is used to indicate that it should be silent
1029 void FixClientCvars(entity e)
1031 // send prediction settings to the client
1032 stuffcmd(e, "\nin_bindmap 0 0\n");
1034 stuffcmd(e, "cl_cmd settemp cl_movecliptokeyboard 2\n");
1035 if(autocvar_g_antilag == 3) // client side hitscan
1036 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
1037 if(autocvar_sv_gentle)
1038 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
1041 float PlayerInIDList(entity p, string idlist)
1046 // NOTE: we do NOT check crypto_idfp_signed here, an unsigned ID is fine too for this
1050 // this function allows abbreviated player IDs too!
1051 n = tokenize_console(idlist);
1052 for(i = 0; i < n; ++i)
1055 if(s == substring(p.crypto_idfp, 0, strlen(s)))
1062 #ifdef DP_EXT_PRECONNECT
1067 Called once (not at each match start) when a client begins a connection to the server
1070 void ClientPreConnect (void)
1072 if(autocvar_sv_eventlog)
1074 GameLogEcho(sprintf(":connect:%d:%d:%s",
1076 num_for_edict(self),
1077 ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot")
1087 Called when a client connects to the server
1090 void DecodeLevelParms (void);
1091 //void dom_player_join_team(entity pl);
1092 void set_dom_state(entity e);
1093 void ClientConnect (void)
1099 print("Warning: ClientConnect, but already connected!\n");
1103 if(Ban_MaybeEnforceBanOnce(self))
1109 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_WATERMARK, WATERMARK);
1112 self.classname = "player_joining";
1114 self.flags = FL_CLIENT;
1115 self.version_nagtime = time + 10 + random() * 10;
1119 dprint("BUG player count is lower than zero, this cannot happen!\n");
1123 if(IS_REAL_CLIENT(self)) { PlayerStats_PlayerBasic_CheckUpdate(self); }
1125 PlayerScore_Attach(self);
1126 ClientData_Attach();
1127 accuracy_init(self);
1129 bot_clientconnect();
1135 // identify the right forced team
1136 if(autocvar_g_campaign)
1138 if(IS_REAL_CLIENT(self)) // only players, not bots
1140 switch(autocvar_g_campaign_forceteam)
1142 case 1: self.team_forced = NUM_TEAM_1; break;
1143 case 2: self.team_forced = NUM_TEAM_2; break;
1144 case 3: self.team_forced = NUM_TEAM_3; break;
1145 case 4: self.team_forced = NUM_TEAM_4; break;
1146 default: self.team_forced = 0;
1150 else if(PlayerInIDList(self, autocvar_g_forced_team_red))
1151 self.team_forced = NUM_TEAM_1;
1152 else if(PlayerInIDList(self, autocvar_g_forced_team_blue))
1153 self.team_forced = NUM_TEAM_2;
1154 else if(PlayerInIDList(self, autocvar_g_forced_team_yellow))
1155 self.team_forced = NUM_TEAM_3;
1156 else if(PlayerInIDList(self, autocvar_g_forced_team_pink))
1157 self.team_forced = NUM_TEAM_4;
1158 else if(autocvar_g_forced_team_otherwise == "red")
1159 self.team_forced = NUM_TEAM_1;
1160 else if(autocvar_g_forced_team_otherwise == "blue")
1161 self.team_forced = NUM_TEAM_2;
1162 else if(autocvar_g_forced_team_otherwise == "yellow")
1163 self.team_forced = NUM_TEAM_3;
1164 else if(autocvar_g_forced_team_otherwise == "pink")
1165 self.team_forced = NUM_TEAM_4;
1166 else if(autocvar_g_forced_team_otherwise == "spectate")
1167 self.team_forced = -1;
1168 else if(autocvar_g_forced_team_otherwise == "spectator")
1169 self.team_forced = -1;
1171 self.team_forced = 0;
1174 if(self.team_forced > 0)
1175 self.team_forced = 0;
1177 JoinBestTeam(self, false, false); // if the team number is valid, keep it
1179 if((autocvar_sv_spectate == 1) || autocvar_g_campaign || self.team_forced < 0) {
1180 self.classname = "observer";
1184 if(autocvar_g_balance_teams)
1186 self.classname = "player";
1187 campaign_bots_may_start = 1;
1191 self.classname = "observer"; // do it anyway
1196 self.classname = "player";
1197 campaign_bots_may_start = 1;
1201 self.playerid = (playerid_last = playerid_last + 1);
1203 PlayerStats_GameReport_AddEvent(sprintf("kills-%d", self.playerid));
1205 if(IS_BOT_CLIENT(self))
1206 PlayerStats_GameReport_AddPlayer(self);
1208 if(autocvar_sv_eventlog)
1209 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot"), ":", self.netname));
1211 LogTeamchange(self.playerid, self.team, 1);
1213 self.just_joined = true; // stop spamming the eventlog with additional lines when the client connects
1215 self.netname_previous = strzone(self.netname);
1217 if(IS_PLAYER(self) && teamplay)
1218 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT_4(self, INFO_JOIN_CONNECT_TEAM_), self.netname);
1220 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_JOIN_CONNECT, self.netname);
1222 stuffcmd(self, strcat(clientstuff, "\n"));
1223 stuffcmd(self, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1225 FixClientCvars(self);
1227 // spawnfunc_waypoint sprites
1228 WaypointSprite_InitClient(self);
1230 // Wazat's grappling hook
1231 SetGrappleHookBindings();
1234 stuffcmd(self, "alias +jetpack +button10\n");
1235 stuffcmd(self, "alias -jetpack -button10\n");
1237 // get version info from player
1238 stuffcmd(self, "cmd clientversion $gameversion\n");
1240 // get other cvars from player
1243 // notify about available teams
1246 CheckAllowedTeams(self);
1247 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1248 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1251 stuffcmd(self, "set _teams_available 0\n");
1255 bot_relinkplayerlist();
1257 self.spectatortime = time;
1260 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1263 self.jointime = time;
1264 self.allowed_timeouts = autocvar_sv_timeout_number;
1266 if(IS_REAL_CLIENT(self))
1268 if(!autocvar_g_campaign)
1270 self.motd_actived_time = -1;
1271 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1274 if(autocvar_g_bugrigs || (g_weaponarena_weapons == WEPSET_TUBA))
1275 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1278 if(!sv_foginterval && world.fog != "")
1279 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1281 W_HitPlotOpen(self);
1283 if(autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)) && !g_ca && !g_cts && !g_race) // teamnagger is currently bad for ca, race & cts
1284 send_CSQC_teamnagger();
1288 CSQCMODEL_AUTOINIT();
1290 self.model_randomizer = random();
1292 if(IS_REAL_CLIENT(self))
1295 for (entity e = world; (e = findfloat(e, init_for_player_needed, 1)); ) {
1296 entity oldself = self;
1298 e.init_for_player(oldself);
1302 MUTATOR_CALLHOOK(ClientConnect);
1308 Called when a client disconnects from the server
1311 .entity chatbubbleentity;
1313 void ClientDisconnect (void)
1316 vehicles_exit(VHEF_RELESE);
1318 if (!IS_CLIENT(self))
1320 print("Warning: ClientDisconnect without ClientConnect\n");
1324 PlayerStats_GameReport_FinalizePlayer(self);
1326 SetSpectator(self, world);
1328 if(IS_PLAYER(self)) { pointparticles(particleeffectnum("spawn_event_neutral"), self.origin, '0 0 0', 1); }
1330 CheatShutdownClient();
1332 W_HitPlotClose(self);
1335 anticheat_shutdown();
1337 playerdemo_shutdown();
1339 bot_clientdisconnect();
1344 if(autocvar_sv_eventlog)
1345 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1347 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, self.netname);
1349 MUTATOR_CALLHOOK(ClientDisconnect);
1351 Portal_ClearAll(self);
1355 RemoveGrapplingHook(self);
1357 // Here, everything has been done that requires this player to be a client.
1359 self.flags &= ~FL_CLIENT;
1361 if (self.chatbubbleentity)
1362 remove (self.chatbubbleentity);
1364 if (self.killindicator)
1365 remove (self.killindicator);
1367 WaypointSprite_PlayerGone();
1369 bot_relinkplayerlist();
1371 accuracy_free(self);
1372 ClientData_Detach();
1373 PlayerScore_Detach(self);
1375 if(self.netname_previous)
1376 strunzone(self.netname_previous);
1377 if(self.clientstatus)
1378 strunzone(self.clientstatus);
1379 if(self.weaponorder_byimpulse)
1380 strunzone(self.weaponorder_byimpulse);
1382 ClearPlayerSounds();
1385 remove(self.personal);
1395 void ChatBubbleThink()
1397 self.nextthink = time;
1398 if ((self.owner.alpha < 0) || self.owner.chatbubbleentity != self)
1400 if(self.owner) // but why can that ever be world?
1401 self.owner.chatbubbleentity = world;
1405 if ((self.owner.BUTTON_CHAT && !self.owner.deadflag)
1407 || self.owner.tetris_on
1410 self.model = self.mdl;
1415 void UpdateChatBubble()
1419 // spawn a chatbubble entity if needed
1420 if (!self.chatbubbleentity)
1422 self.chatbubbleentity = spawn();
1423 self.chatbubbleentity.owner = self;
1424 self.chatbubbleentity.exteriormodeltoclient = self;
1425 self.chatbubbleentity.think = ChatBubbleThink;
1426 self.chatbubbleentity.nextthink = time;
1427 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1428 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1429 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs.z * '0 0 1');
1430 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1431 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1432 self.chatbubbleentity.model = "";
1433 self.chatbubbleentity.effects = EF_LOWPRECISION;
1438 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1439 // added to the model skins
1440 /*void UpdateColorModHack()
1443 c = self.clientcolors & 15;
1444 // LordHavoc: only bothering to support white, green, red, yellow, blue
1445 if (!teamplay) self.colormod = '0 0 0';
1446 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1447 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1448 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1449 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1450 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1451 else self.colormod = '1 1 1';
1456 if(self.alpha >= 0 && autocvar_g_respawn_ghosts)
1458 self.solid = SOLID_NOT;
1459 self.takedamage = DAMAGE_NO;
1460 self.movetype = MOVETYPE_FLY;
1461 self.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1462 self.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1463 self.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1464 pointparticles(particleeffectnum("respawn_ghost"), self.origin, '0 0 0', 1);
1465 if(autocvar_g_respawn_ghosts_maxtime)
1466 SUB_SetFade (self, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1471 self.effects |= EF_NODRAW; // prevent another CopyBody
1472 PutClientInServer();
1475 void play_countdown(float finished, string samp)
1477 if(IS_REAL_CLIENT(self))
1478 if(floor(finished - time - frametime) != floor(finished - time))
1479 if(finished - time < 6)
1480 sound (self, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
1483 void player_powerups (void)
1485 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1486 olditems = self.items;
1488 if((self.items & IT_USING_JETPACK) && !self.deadflag && !gameover)
1489 self.modelflags |= MF_ROCKET;
1491 self.modelflags &= ~MF_ROCKET;
1493 self.effects &= ~(EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1495 if((self.alpha < 0 || self.deadflag) && !self.vehicle) // don't apply the flags if the player is gibbed
1498 Fire_ApplyDamage(self);
1499 Fire_ApplyEffect(self);
1503 if (self.items & IT_STRENGTH)
1505 play_countdown(self.strength_finished, "misc/poweroff.wav");
1506 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1507 if (time > self.strength_finished)
1509 self.items = self.items - (self.items & IT_STRENGTH);
1510 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, self.netname);
1511 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
1516 if (time < self.strength_finished)
1518 self.items = self.items | IT_STRENGTH;
1519 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, self.netname);
1520 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_STRENGTH);
1523 if (self.items & IT_INVINCIBLE)
1525 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1526 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1527 if (time > self.invincible_finished)
1529 self.items = self.items - (self.items & IT_INVINCIBLE);
1530 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, self.netname);
1531 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
1536 if (time < self.invincible_finished)
1538 self.items = self.items | IT_INVINCIBLE;
1539 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, self.netname);
1540 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SHIELD);
1543 if (self.items & IT_SUPERWEAPON)
1545 if (!(self.weapons & WEPSET_SUPERWEAPONS))
1547 self.superweapons_finished = 0;
1548 self.items = self.items - (self.items & IT_SUPERWEAPON);
1549 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, self.netname);
1550 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1552 else if (self.items & IT_UNLIMITED_SUPERWEAPONS)
1554 // don't let them run out
1558 play_countdown(self.superweapons_finished, "misc/poweroff.wav");
1559 if (time > self.superweapons_finished)
1561 self.items = self.items - (self.items & IT_SUPERWEAPON);
1562 self.weapons &= ~WEPSET_SUPERWEAPONS;
1563 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, self.netname);
1564 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1568 else if(self.weapons & WEPSET_SUPERWEAPONS)
1570 if (time < self.superweapons_finished || (self.items & IT_UNLIMITED_SUPERWEAPONS))
1572 self.items = self.items | IT_SUPERWEAPON;
1573 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, self.netname);
1574 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1578 self.superweapons_finished = 0;
1579 self.weapons &= ~WEPSET_SUPERWEAPONS;
1584 self.superweapons_finished = 0;
1588 if(autocvar_g_nodepthtestplayers)
1589 self.effects = self.effects | EF_NODEPTHTEST;
1591 if(autocvar_g_fullbrightplayers)
1592 self.effects = self.effects | EF_FULLBRIGHT;
1594 if (time >= game_starttime)
1595 if (time < self.spawnshieldtime)
1596 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1598 MUTATOR_CALLHOOK(PlayerPowerups);
1601 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1603 if(current > stable)
1605 else if(current > stable - 0.25) // when close enough, "snap"
1608 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1611 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1613 if(current < stable)
1615 else if(current < stable + 0.25) // when close enough, "snap"
1618 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1621 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1623 if(current > rotstable)
1625 if(rotframetime > 0)
1627 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1628 current = max(rotstable, current - rotlinear * rotframetime);
1631 else if(current < regenstable)
1633 if(regenframetime > 0)
1635 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1636 current = min(regenstable, current + regenlinear * regenframetime);
1646 void player_regen (void)
1648 float max_mod, regen_mod, rot_mod, limit_mod;
1649 max_mod = regen_mod = rot_mod = limit_mod = 1;
1650 regen_mod_max = max_mod;
1651 regen_mod_regen = regen_mod;
1652 regen_mod_rot = rot_mod;
1653 regen_mod_limit = limit_mod;
1654 if(!MUTATOR_CALLHOOK(PlayerRegen))
1657 float minh, mina, maxh, maxa, limith, limita;
1658 maxh = autocvar_g_balance_health_rotstable;
1659 maxa = autocvar_g_balance_armor_rotstable;
1660 minh = autocvar_g_balance_health_regenstable;
1661 mina = autocvar_g_balance_armor_regenstable;
1662 limith = autocvar_g_balance_health_limit;
1663 limita = autocvar_g_balance_armor_limit;
1665 max_mod = regen_mod_max;
1666 regen_mod = regen_mod_regen;
1667 rot_mod = regen_mod_rot;
1668 limit_mod = regen_mod_limit;
1670 maxh = maxh * max_mod;
1671 minh = minh * max_mod;
1672 limith = limith * limit_mod;
1673 limita = limita * limit_mod;
1675 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);
1676 self.health = CalcRotRegen(self.health, minh, autocvar_g_balance_health_regen, autocvar_g_balance_health_regenlinear, regen_mod * frametime * (time > self.pauseregen_finished), maxh, autocvar_g_balance_health_rot, autocvar_g_balance_health_rotlinear, rot_mod * frametime * (time > self.pauserothealth_finished), limith);
1679 // if player rotted to death... die!
1680 // check this outside above checks, as player may still be able to rot to death
1682 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1684 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
1686 float minf, maxf, limitf;
1688 maxf = autocvar_g_balance_fuel_rotstable;
1689 minf = autocvar_g_balance_fuel_regenstable;
1690 limitf = autocvar_g_balance_fuel_limit;
1692 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 & IT_FUEL_REGEN) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > self.pauserotfuel_finished), limitf);
1696 float zoomstate_set;
1697 void SetZoomState(float z)
1699 if(z != self.zoomstate)
1702 ClientData_Touch(self);
1707 void GetPressedKeys(void) {
1708 MUTATOR_CALLHOOK(GetPressedKeys);
1709 if (self.movement.x > 0) // get if movement keys are pressed
1710 { // forward key pressed
1711 self.pressedkeys |= KEY_FORWARD;
1712 self.pressedkeys &= ~KEY_BACKWARD;
1714 else if (self.movement.x < 0)
1715 { // backward key pressed
1716 self.pressedkeys |= KEY_BACKWARD;
1717 self.pressedkeys &= ~KEY_FORWARD;
1721 self.pressedkeys &= ~KEY_FORWARD;
1722 self.pressedkeys &= ~KEY_BACKWARD;
1725 if (self.movement.y > 0)
1726 { // right key pressed
1727 self.pressedkeys |= KEY_RIGHT;
1728 self.pressedkeys &= ~KEY_LEFT;
1730 else if (self.movement.y < 0)
1731 { // left key pressed
1732 self.pressedkeys |= KEY_LEFT;
1733 self.pressedkeys &= ~KEY_RIGHT;
1737 self.pressedkeys &= ~KEY_RIGHT;
1738 self.pressedkeys &= ~KEY_LEFT;
1741 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1742 self.pressedkeys |= KEY_JUMP;
1744 self.pressedkeys &= ~KEY_JUMP;
1745 if (self.BUTTON_CROUCH)
1746 self.pressedkeys |= KEY_CROUCH;
1748 self.pressedkeys &= ~KEY_CROUCH;
1750 if (self.BUTTON_ATCK)
1751 self.pressedkeys |= KEY_ATCK;
1753 self.pressedkeys &= ~KEY_ATCK;
1754 if (self.BUTTON_ATCK2)
1755 self.pressedkeys |= KEY_ATCK2;
1757 self.pressedkeys &= ~KEY_ATCK2;
1761 ======================
1762 spectate mode routines
1763 ======================
1766 void SpectateCopy(entity spectatee) {
1768 MUTATOR_CALLHOOK(SpectateCopy);
1769 self.armortype = spectatee.armortype;
1770 self.armorvalue = spectatee.armorvalue;
1771 self.ammo_cells = spectatee.ammo_cells;
1772 self.ammo_plasma = spectatee.ammo_plasma;
1773 self.ammo_shells = spectatee.ammo_shells;
1774 self.ammo_nails = spectatee.ammo_nails;
1775 self.ammo_rockets = spectatee.ammo_rockets;
1776 self.ammo_fuel = spectatee.ammo_fuel;
1777 self.clip_load = spectatee.clip_load;
1778 self.clip_size = spectatee.clip_size;
1779 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1780 self.health = spectatee.health;
1782 self.items = spectatee.items;
1783 self.last_pickup = spectatee.last_pickup;
1784 self.hit_time = spectatee.hit_time;
1785 self.metertime = spectatee.metertime;
1786 self.strength_finished = spectatee.strength_finished;
1787 self.invincible_finished = spectatee.invincible_finished;
1788 self.pressedkeys = spectatee.pressedkeys;
1789 self.weapons = spectatee.weapons;
1790 self.switchweapon = spectatee.switchweapon;
1791 self.switchingweapon = spectatee.switchingweapon;
1792 self.weapon = spectatee.weapon;
1793 self.vortex_charge = spectatee.vortex_charge;
1794 self.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
1795 self.hagar_load = spectatee.hagar_load;
1796 self.arc_heat_percent = spectatee.arc_heat_percent;
1797 self.minelayer_mines = spectatee.minelayer_mines;
1798 self.punchangle = spectatee.punchangle;
1799 self.view_ofs = spectatee.view_ofs;
1800 self.velocity = spectatee.velocity;
1801 self.dmg_take = spectatee.dmg_take;
1802 self.dmg_save = spectatee.dmg_save;
1803 self.dmg_inflictor = spectatee.dmg_inflictor;
1804 self.v_angle = spectatee.v_angle;
1805 self.angles = spectatee.v_angle;
1806 self.frozen = spectatee.frozen;
1807 self.revive_progress = spectatee.revive_progress;
1808 if(!self.BUTTON_USE)
1809 self.fixangle = true;
1810 setorigin(self, spectatee.origin);
1811 setsize(self, spectatee.mins, spectatee.maxs);
1812 SetZoomState(spectatee.zoomstate);
1814 anticheat_spectatecopy(spectatee);
1815 self.hud = spectatee.hud;
1816 if(spectatee.vehicle)
1818 self.fixangle = false;
1819 //self.velocity = spectatee.vehicle.velocity;
1820 self.vehicle_health = spectatee.vehicle_health;
1821 self.vehicle_shield = spectatee.vehicle_shield;
1822 self.vehicle_energy = spectatee.vehicle_energy;
1823 self.vehicle_ammo1 = spectatee.vehicle_ammo1;
1824 self.vehicle_ammo2 = spectatee.vehicle_ammo2;
1825 self.vehicle_reload1 = spectatee.vehicle_reload1;
1826 self.vehicle_reload2 = spectatee.vehicle_reload2;
1830 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1831 WriteAngle(MSG_ONE, spectatee.v_angle.x);
1832 WriteAngle(MSG_ONE, spectatee.v_angle.y);
1833 WriteAngle(MSG_ONE, spectatee.v_angle.z);
1835 //WriteByte (MSG_ONE, SVC_SETVIEW);
1836 // WriteEntity(MSG_ONE, self);
1837 //makevectors(spectatee.v_angle);
1838 //setorigin(self, spectatee.origin - v_forward * 400 + v_up * 300);*/
1842 float SpectateUpdate()
1847 if(!IS_PLAYER(self.enemy) || self == self.enemy)
1849 SetSpectator(self, world);
1853 SpectateCopy(self.enemy);
1860 if(!IS_PLAYER(self.enemy))
1863 ClientData_Touch(self.enemy);
1866 WriteByte(MSG_ONE, SVC_SETVIEW);
1867 WriteEntity(MSG_ONE, self.enemy);
1868 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1869 self.movetype = MOVETYPE_NONE;
1870 accuracy_resend(self);
1872 if(!SpectateUpdate())
1873 PutObserverInServer();
1878 void SetSpectator(entity player, entity spectatee)
1880 entity old_spectatee = player.enemy;
1882 player.enemy = spectatee;
1885 // these are required to fix the spectator bug with arc
1886 if(old_spectatee && old_spectatee.arc_beam) { old_spectatee.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1887 if(player.enemy && player.enemy.arc_beam) { player.enemy.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1889 // needed to update spectator list
1890 if(old_spectatee) { ClientData_Touch(old_spectatee); }
1893 float Spectate(entity pl)
1895 if(g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer)
1896 if(DIFF_TEAM(pl, self))
1899 SetSpectator(self, pl);
1900 return SpectateSet();
1903 // Returns next available player to spectate if g_ca_spectate_enemies == 0
1904 entity CA_SpectateNext(entity start)
1906 if(SAME_TEAM(start, self)) { return start; }
1909 // continue from current player
1910 while(other && DIFF_TEAM(other, self))
1911 other = find(other, classname, "player");
1915 // restart from begining
1916 other = find(other, classname, "player");
1917 while(other && DIFF_TEAM(other, self))
1918 other = find(other, classname, "player");
1924 float SpectateNext()
1926 other = find(self.enemy, classname, "player");
1928 if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer)
1930 // CA and ca players when spectating enemies is forbidden
1931 other = CA_SpectateNext(other);
1935 // other modes and ca spectators or spectating enemies is allowed
1937 other = find(other, classname, "player");
1940 if(other) { SetSpectator(self, other); }
1942 return SpectateSet();
1945 float SpectatePrev()
1947 // NOTE: chain order is from the highest to the lower entnum (unlike find)
1948 other = findchain(classname, "player");
1949 if (!other) // no player
1952 entity first = other;
1953 // skip players until current spectated player
1955 while(other && other != self.enemy)
1956 other = other.chain;
1958 if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer)
1960 do { other = other.chain; }
1961 while(other && other.team != self.team);
1966 while(other.team != self.team)
1967 other = other.chain;
1968 if(other == self.enemy)
1975 other = other.chain;
1979 SetSpectator(self, other);
1980 return SpectateSet();
1985 ShowRespawnCountdown()
1987 Update a respawn countdown display.
1990 void ShowRespawnCountdown()
1993 if(self.deadflag == DEAD_NO) // just respawned?
1997 number = ceil(self.respawn_time - time);
2000 if(number <= self.respawn_countdown)
2002 self.respawn_countdown = number - 1;
2003 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
2004 { Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(CNT_RESPAWN, number)); }
2009 void LeaveSpectatorMode()
2013 if(nJoinAllowed(self))
2015 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0)
2017 self.classname = "player";
2018 nades_RemoveBonus(self);
2020 SetSpectator(self, world);
2022 if(autocvar_g_campaign || autocvar_g_balance_teams)
2023 { JoinBestTeam(self, false, true); }
2025 if(autocvar_g_campaign)
2026 { campaign_bots_may_start = 1; }
2028 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_PREVENT_JOIN);
2030 PutClientInServer();
2032 if(IS_PLAYER(self)) { Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_JOIN_PLAY, self.netname); }
2035 stuffcmd(self, "menu_showteamselect\n");
2039 // Player may not join because g_maxplayers is set
2040 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_JOIN_PREVENT);
2045 * Determines whether the player is allowed to join. This depends on cvar
2046 * g_maxplayers, if it isn't used this function always return true, otherwise
2047 * it checks whether the number of currently playing players exceeds g_maxplayers.
2048 * @return int number of free slots for players, 0 if none
2050 float nJoinAllowed(entity ignore) {
2052 // this is called that way when checking if anyone may be able to join (to build qcstatus)
2053 // so report 0 free slots if restricted
2055 if(autocvar_g_forced_team_otherwise == "spectate")
2057 if(autocvar_g_forced_team_otherwise == "spectator")
2061 if(self.team_forced < 0)
2062 return 0; // forced spectators can never join
2064 // TODO simplify this
2066 float totalClients = 0;
2071 if (!autocvar_g_maxplayers)
2072 return maxclients - totalClients;
2074 float currentlyPlaying = 0;
2075 FOR_EACH_REALCLIENT(e)
2076 if(IS_PLAYER(e) || e.caplayer)
2077 currentlyPlaying += 1;
2079 if(currentlyPlaying < autocvar_g_maxplayers)
2080 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
2086 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2087 * g_maxplayers_spectator_blocktime seconds
2089 void checkSpectatorBlock() {
2090 if(IS_SPEC(self) || IS_OBSERVER(self))
2092 if(IS_REAL_CLIENT(self))
2094 if( time > (self.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
2095 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
2101 void PrintWelcomeMessage()
2103 if(self.motd_actived_time == 0)
2105 if (autocvar_g_campaign) {
2106 if ((IS_PLAYER(self) && self.BUTTON_INFO) || (!IS_PLAYER(self))) {
2107 self.motd_actived_time = time;
2108 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, campaign_message);
2111 if (self.BUTTON_INFO) {
2112 self.motd_actived_time = time;
2113 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
2117 else if(self.motd_actived_time > 0) // showing MOTD or campaign message
2119 if (autocvar_g_campaign) {
2120 if (self.BUTTON_INFO)
2121 self.motd_actived_time = time;
2122 else if ((time - self.motd_actived_time > 2) && IS_PLAYER(self)) { // hide it some seconds after BUTTON_INFO has been released
2123 self.motd_actived_time = 0;
2124 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2127 if (self.BUTTON_INFO)
2128 self.motd_actived_time = time;
2129 else if (time - self.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
2130 self.motd_actived_time = 0;
2131 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2135 else //if(self.motd_actived_time < 0) // just connected, motd is active
2137 if(self.BUTTON_INFO) // BUTTON_INFO hides initial MOTD
2138 self.motd_actived_time = -2; // wait until BUTTON_INFO gets released
2139 else if(self.motd_actived_time == -2 || IS_PLAYER(self))
2141 // instanctly hide MOTD
2142 self.motd_actived_time = 0;
2143 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2148 void ObserverThink()
2150 float prefered_movetype;
2151 if (self.flags & FL_JUMPRELEASED) {
2152 if (self.BUTTON_JUMP && !self.version_mismatch) {
2153 self.flags &= ~FL_JUMPRELEASED;
2154 self.flags |= FL_SPAWNING;
2155 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2156 self.flags &= ~FL_JUMPRELEASED;
2157 if(SpectateNext()) {
2158 self.classname = "spectator";
2161 prefered_movetype = ((!self.BUTTON_USE ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
2162 if (self.movetype != prefered_movetype)
2163 self.movetype = prefered_movetype;
2166 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2167 self.flags |= FL_JUMPRELEASED;
2168 if(self.flags & FL_SPAWNING)
2170 self.flags &= ~FL_SPAWNING;
2171 LeaveSpectatorMode();
2178 void SpectatorThink()
2180 if (self.flags & FL_JUMPRELEASED) {
2181 if (self.BUTTON_JUMP && !self.version_mismatch) {
2182 self.flags &= ~FL_JUMPRELEASED;
2183 self.flags |= FL_SPAWNING;
2184 } else if(self.BUTTON_ATCK || self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209)) {
2185 self.flags &= ~FL_JUMPRELEASED;
2186 if(SpectateNext()) {
2187 self.classname = "spectator";
2189 self.classname = "observer";
2190 PutClientInServer();
2193 } else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229)) {
2194 self.flags &= ~FL_JUMPRELEASED;
2195 if(SpectatePrev()) {
2196 self.classname = "spectator";
2198 self.classname = "observer";
2199 PutClientInServer();
2202 } else if (self.BUTTON_ATCK2) {
2203 self.flags &= ~FL_JUMPRELEASED;
2204 self.classname = "observer";
2205 PutClientInServer();
2207 if(!SpectateUpdate())
2208 PutObserverInServer();
2211 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2212 self.flags |= FL_JUMPRELEASED;
2213 if(self.flags & FL_SPAWNING)
2215 self.flags &= ~FL_SPAWNING;
2216 LeaveSpectatorMode();
2220 if(!SpectateUpdate())
2221 PutObserverInServer();
2224 self.flags |= FL_CLIENT | FL_NOTARGET;
2229 if (!IS_PLAYER(self))
2234 vehicles_exit(VHEF_NORMAL);
2238 // a use key was pressed; call handlers
2239 MUTATOR_CALLHOOK(PlayerUseKey);
2242 float isInvisibleString(string s)
2245 s = strdecolorize(s);
2246 for((i = 0), (n = strlen(s)); i < n; ++i)
2254 case 192: // charmap space
2255 if (!autocvar_utf8_enable)
2258 case 160: // space in unicode fonts
2259 case 0xE000 + 192: // utf8 charmap space
2260 if (autocvar_utf8_enable)
2273 Called every frame for each client before the physics are run
2276 .float usekeypressed;
2277 void() nexball_setstatus;
2279 void PlayerPreThink (void)
2281 WarpZone_PlayerPhysics_FixVAngle();
2283 self.stat_game_starttime = game_starttime;
2284 self.stat_round_starttime = round_starttime;
2285 self.stat_allow_oldvortexbeam = autocvar_g_allow_oldvortexbeam;
2286 self.stat_leadlimit = autocvar_leadlimit;
2290 // physics frames: update anticheat stuff
2291 anticheat_prethink();
2294 if(blockSpectators && frametime)
2295 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2296 checkSpectatorBlock();
2300 // Savage: Check for nameless players
2301 if (isInvisibleString(self.netname)) {
2302 string new_name = strzone(strcat("Player@", ftos(self.playerid)));
2303 if(autocvar_sv_eventlog)
2304 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", new_name));
2305 if(self.netname_previous)
2306 strunzone(self.netname_previous);
2307 self.netname_previous = strzone(new_name);
2308 self.netname = self.netname_previous;
2309 // stuffcmd(self, strcat("name ", self.netname, "\n"));
2310 } else if(self.netname_previous != self.netname) {
2311 if(autocvar_sv_eventlog)
2312 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2313 if(self.netname_previous)
2314 strunzone(self.netname_previous);
2315 self.netname_previous = strzone(self.netname);
2319 if(self.version_nagtime)
2320 if(self.cvar_g_xonoticversion)
2321 if(time > self.version_nagtime)
2323 // don't notify git users
2324 if(strstr(self.cvar_g_xonoticversion, "git", 0) < 0 && strstr(self.cvar_g_xonoticversion, "autobuild", 0) < 0)
2326 if(strstr(autocvar_g_xonoticversion, "git", 0) >= 0 || strstr(autocvar_g_xonoticversion, "autobuild", 0) >= 0)
2328 // notify release users if connecting to git
2329 dprint("^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");
2330 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2335 r = vercmp(self.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2338 // give users new version
2339 dprint("^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");
2340 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2344 // notify users about old server version
2345 print("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", autocvar_g_xonoticversion, "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2346 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2350 self.version_nagtime = 0;
2354 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2356 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_GODMODE_OFF, self.max_armorvalue);
2357 self.max_armorvalue = 0;
2361 if (TetrisPreFrame())
2365 if(self.frozen == 2)
2367 self.revive_progress = bound(0, self.revive_progress + frametime * self.revive_speed, 1);
2368 self.health = max(1, self.revive_progress * start_health);
2369 self.iceblock.alpha = bound(0.2, 1 - self.revive_progress, 1);
2371 if(self.revive_progress >= 1)
2374 else if(self.frozen == 3)
2376 self.revive_progress = bound(0, self.revive_progress - frametime * self.revive_speed, 1);
2377 self.health = max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * self.revive_progress );
2382 vehicles_exit(VHEF_RELESE);
2383 self.event_damage(self, self.frozen_by, 1, DEATH_NADE_ICE_FREEZE, self.origin, '0 0 0');
2385 else if ( self.revive_progress <= 0 )
2389 MUTATOR_CALLHOOK(PlayerPreThink);
2391 if(!self.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2393 if(self.BUTTON_USE && !self.usekeypressed)
2395 self.usekeypressed = self.BUTTON_USE;
2398 if(IS_REAL_CLIENT(self))
2399 PrintWelcomeMessage();
2404 CheckRules_Player();
2406 if (intermission_running)
2408 IntermissionThink (); // otherwise a button could be missed between
2409 return; // the think tics
2412 //don't allow the player to turn around while game is paused!
2413 if(timeout_status == TIMEOUT_ACTIVE) {
2414 // FIXME turn this into CSQC stuff
2415 self.v_angle = self.lastV_angle;
2416 self.angles = self.lastV_angle;
2417 self.fixangle = true;
2422 if(self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge))
2424 self.weaponentity_glowmod_x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
2425 self.weaponentity_glowmod_y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
2426 self.weaponentity_glowmod_z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
2428 if(self.vortex_charge > WEP_CVAR(vortex, charge_animlimit))
2430 self.weaponentity_glowmod_x = self.weaponentity_glowmod.x + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
2431 self.weaponentity_glowmod_y = self.weaponentity_glowmod.y + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
2432 self.weaponentity_glowmod_z = self.weaponentity_glowmod.z + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
2436 self.weaponentity_glowmod = colormapPaletteColor(self.clientcolors & 0x0F, true) * 2;
2441 if (self.deadflag != DEAD_NO)
2443 if(self.personal && g_race_qualifying)
2445 if(time > self.respawn_time)
2447 self.respawn_time = time + 1; // only retry once a second
2448 self.stat_respawn_time = self.respawn_time;
2455 float button_pressed;
2458 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2460 if (self.deadflag == DEAD_DYING)
2462 if((self.respawn_flags & RESPAWN_FORCE) && !autocvar_g_respawn_delay_max)
2463 self.deadflag = DEAD_RESPAWNING;
2464 else if(!button_pressed)
2465 self.deadflag = DEAD_DEAD;
2467 else if (self.deadflag == DEAD_DEAD)
2470 self.deadflag = DEAD_RESPAWNABLE;
2471 else if(time >= self.respawn_time_max && (self.respawn_flags & RESPAWN_FORCE))
2472 self.deadflag = DEAD_RESPAWNING;
2474 else if (self.deadflag == DEAD_RESPAWNABLE)
2477 self.deadflag = DEAD_RESPAWNING;
2479 else if (self.deadflag == DEAD_RESPAWNING)
2481 if(time > self.respawn_time)
2483 self.respawn_time = time + 1; // only retry once a second
2484 self.respawn_time_max = self.respawn_time;
2489 ShowRespawnCountdown();
2491 if(self.respawn_flags & RESPAWN_SILENT)
2492 self.stat_respawn_time = 0;
2493 else if((self.respawn_flags & RESPAWN_FORCE) && autocvar_g_respawn_delay_max)
2494 self.stat_respawn_time = self.respawn_time_max;
2496 self.stat_respawn_time = self.respawn_time;
2499 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2500 if(self.deadflag == DEAD_RESPAWNING && self.stat_respawn_time > 0)
2501 self.stat_respawn_time *= -1;
2506 self.prevorigin = self.origin;
2508 float do_crouch = self.BUTTON_CROUCH;
2516 // WEAPONTODO: THIS SHIT NEEDS TO GO EVENTUALLY
2517 // It cannot be predicted by the engine!
2518 if((self.weapon == WEP_SHOCKWAVE || self.weapon == WEP_SHOTGUN) && self.weaponentity.wframe == WFRAME_FIRE2 && time < self.weapon_nextthink)
2526 self.view_ofs = PL_CROUCH_VIEW_OFS;
2527 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2528 // setanim(self, self.anim_duck, false, true, true); // this anim is BROKEN anyway
2535 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, false, self);
2536 if (!trace_startsolid)
2538 self.crouch = false;
2539 self.view_ofs = PL_VIEW_OFS;
2540 setsize (self, PL_MIN, PL_MAX);
2547 GrapplingHookFrame();
2549 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2552 self.items &= ~self.items_added;
2556 self.items_added = 0;
2557 if(self.items & IT_JETPACK)
2558 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2559 self.items_added |= IT_FUEL;
2561 self.items |= self.items_added;
2566 // WEAPONTODO: Add a weapon request for this
2567 // rot vortex charge to the charge limit
2568 if(WEP_CVAR(vortex, charge_rot_rate) && self.vortex_charge > WEP_CVAR(vortex, charge_limit) && self.vortex_charge_rottime < time)
2569 self.vortex_charge = bound(WEP_CVAR(vortex, charge_limit), self.vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1);
2575 secrets_setstatus();
2578 monsters_setstatus();
2580 self.dmg_team = max(0, self.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2582 //self.angles_y=self.v_angle_y + 90; // temp
2583 } else if(gameover) {
2584 if (intermission_running)
2585 IntermissionThink (); // otherwise a button could be missed between
2587 } else if(IS_OBSERVER(self)) {
2589 } else if(IS_SPEC(self)) {
2593 // WEAPONTODO: Add weapon request for this
2595 SetZoomState(self.BUTTON_ZOOM || self.BUTTON_ZOOMSCRIPT || (self.BUTTON_ATCK2 && self.weapon == WEP_VORTEX) || (self.BUTTON_ATCK2 && self.weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0)); // WEAPONTODO
2597 float oldspectatee_status;
2598 oldspectatee_status = self.spectatee_status;
2600 self.spectatee_status = num_for_edict(self.enemy);
2601 else if(IS_OBSERVER(self))
2602 self.spectatee_status = num_for_edict(self);
2604 self.spectatee_status = 0;
2605 if(self.spectatee_status != oldspectatee_status)
2607 ClientData_Touch(self);
2610 if(self.teamkill_soundtime)
2611 if(time > self.teamkill_soundtime)
2613 self.teamkill_soundtime = 0;
2615 entity oldpusher, oldself;
2617 oldself = self; self = self.teamkill_soundsource;
2618 oldpusher = self.pusher; self.pusher = oldself;
2620 PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2622 self.pusher = oldpusher;
2626 if(self.taunt_soundtime)
2627 if(time > self.taunt_soundtime)
2629 self.taunt_soundtime = 0;
2630 PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2633 target_voicescript_next(self);
2635 // WEAPONTODO: Move into weaponsystem somehow
2636 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2638 self.clip_load = self.clip_size = 0;
2645 Called every frame for each client after the physics are run
2648 .float idlekick_lasttimeleft;
2649 void PlayerPostThink (void)
2651 if(sv_maxidle > 0 && frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2652 if(IS_PLAYER(self) || sv_maxidle_spectatorsareidle)
2654 if (time - self.parm_idlesince < 1) // instead of (time == self.parm_idlesince) to support sv_maxidle <= 10
2656 if(self.idlekick_lasttimeleft)
2658 self.idlekick_lasttimeleft = 0;
2659 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_IDLING);
2665 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2666 if(timeleft == min(10, sv_maxidle - 1)) // - 1 to support sv_maxidle <= 10
2668 if(!self.idlekick_lasttimeleft)
2669 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
2673 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_KICK_IDLING, self.netname);
2677 else if(timeleft <= 10)
2679 if(timeleft != self.idlekick_lasttimeleft)
2680 { Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(CNT_IDLE, timeleft)); }
2681 self.idlekick_lasttimeleft = timeleft;
2687 if(self.impulse == 100)
2689 if (!TetrisPostFrame())
2695 //CheckPlayerJump();
2697 if(IS_PLAYER(self)) {
2698 CheckRules_Player();
2702 if (intermission_running)
2703 return; // intermission or finale
2713 for(i = 0; i < 1000; ++i)
2716 end = self.origin + '0 0 1024' + 512 * randomvec();
2717 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2718 if(trace_fraction < 1)
2719 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2721 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2727 if(self.waypointsprite_attachedforcarrier)
2728 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON));
2732 CSQCMODEL_AUTOUPDATE();