3 #include <common/csqcmodel_settings.qh>
4 #include <common/deathtypes/all.qh>
5 #include <common/effects/all.qh>
6 #include <common/effects/qc/globalsound.qh>
7 #include <common/ent_cs.qh>
8 #include <common/gamemodes/_mod.qh>
9 #include <common/gamemodes/gamemode/nexball/sv_nexball.qh>
10 #include <common/items/_mod.qh>
11 #include <common/items/inventory.qh>
12 #include <common/mapobjects/func/conveyor.qh>
13 #include <common/mapobjects/func/ladder.qh>
14 #include <common/mapobjects/subs.qh>
15 #include <common/mapobjects/target/spawnpoint.qh>
16 #include <common/mapobjects/teleporters.qh>
17 #include <common/mapobjects/trigger/counter.qh>
18 #include <common/mapobjects/trigger/secret.qh>
19 #include <common/mapobjects/trigger/swamp.qh>
20 #include <common/mapobjects/triggers.qh>
21 #include <common/minigames/sv_minigames.qh>
22 #include <common/monsters/sv_monsters.qh>
23 #include <common/mutators/mutator/instagib/sv_instagib.qh>
24 #include <common/mutators/mutator/nades/nades.qh>
25 #include <common/mutators/mutator/overkill/oknex.qh>
26 #include <common/mutators/mutator/status_effects/_mod.qh>
27 #include <common/mutators/mutator/waypoints/all.qh>
28 #include <common/net_linked.qh>
29 #include <common/net_notice.qh>
30 #include <common/notifications/all.qh>
31 #include <common/physics/player.qh>
32 #include <common/playerstats.qh>
33 #include <common/state.qh>
34 #include <common/stats.qh>
35 #include <common/vehicles/all.qh>
36 #include <common/vehicles/sv_vehicles.qh>
37 #include <common/viewloc.qh>
38 #include <common/weapons/_all.qh>
39 #include <common/weapons/weapon/vortex.qh>
40 #include <common/wepent.qh>
41 #include <lib/csqcmodel/sv_model.qh>
42 #include <lib/warpzone/common.qh>
43 #include <lib/warpzone/server.qh>
44 #include <server/anticheat.qh>
45 #include <server/antilag.qh>
46 #include <server/bot/api.qh>
47 #include <server/bot/default/cvars.qh>
48 #include <server/campaign.qh>
49 #include <server/chat.qh>
50 #include <server/cheats.qh>
51 #include <server/clientkill.qh>
52 #include <server/command/common.qh>
53 #include <server/command/common.qh>
54 #include <server/command/vote.qh>
55 #include <server/compat/quake3.qh>
56 #include <server/damage.qh>
57 #include <server/gamelog.qh>
58 #include <server/handicap.qh>
59 #include <server/hook.qh>
60 #include <server/impulse.qh>
61 #include <server/intermission.qh>
62 #include <server/ipban.qh>
63 #include <server/main.qh>
64 #include <server/mutators/_mod.qh>
65 #include <server/player.qh>
66 #include <server/portals.qh>
67 #include <server/race.qh>
68 #include <server/resources.qh>
69 #include <server/scores.qh>
70 #include <server/scores_rules.qh>
71 #include <server/spawnpoints.qh>
72 #include <server/teamplay.qh>
73 #include <server/weapons/accuracy.qh>
74 #include <server/weapons/common.qh>
75 #include <server/weapons/hitplot.qh>
76 #include <server/weapons/selection.qh>
77 #include <server/weapons/tracing.qh>
78 #include <server/weapons/weaponsystem.qh>
79 #include <server/world.qh>
81 STATIC_METHOD(Client, Add, void(Client this, int _team))
84 TRANSMUTE(Player, this);
87 PutClientInServer(this);
90 STATIC_METHOD(Client, Remove, void(Client this))
92 TRANSMUTE(Observer, this);
93 PutClientInServer(this);
94 ClientDisconnect(this);
97 void send_CSQC_teamnagger() {
98 WriteHeader(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
101 void send_TeamNames(int channel, entity to) {
104 WriteHeader(channel, TE_CSQC_TEAMNAMES);
105 WriteString(channel, autocvar_g_teamnames_red);
106 WriteString(channel, autocvar_g_teamnames_blue);
107 WriteString(channel, autocvar_g_teamnames_yellow);
108 WriteString(channel, autocvar_g_teamnames_pink);
111 int CountSpectators(entity player, entity to)
113 if(!player) { return 0; } // not sure how, but best to be safe
117 FOREACH_CLIENT(IS_REAL_CLIENT(it) && IS_SPEC(it) && it != to && it.enemy == player,
125 void WriteSpectators(entity player, entity to)
127 if(!player) { return; } // not sure how, but best to be safe
130 FOREACH_CLIENT(IS_REAL_CLIENT(it) && IS_SPEC(it) && it != to && it.enemy == player,
132 if(spec_count >= MAX_SPECTATORS)
134 WriteByte(MSG_ENTITY, num_for_edict(it));
139 bool ClientData_Send(entity this, entity to, int sf)
141 assert(to == this.owner, return false);
144 if (IS_SPEC(e)) e = e.enemy;
147 if (CS(e).race_completed) sf |= BIT(0); // forced scoreboard
148 if (CS(to).spectatee_status) sf |= BIT(1); // spectator ent number follows
149 if (CS(e).zoomstate) sf |= BIT(2); // zoomed
150 if (autocvar_sv_showspectators) sf |= BIT(4); // show spectators
152 WriteHeader(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
153 WriteByte(MSG_ENTITY, sf);
156 WriteByte(MSG_ENTITY, CS(to).spectatee_status);
160 float specs = CountSpectators(e, to);
161 WriteByte(MSG_ENTITY, specs);
162 WriteSpectators(e, to);
168 void ClientData_Attach(entity this)
170 Net_LinkEntity(CS(this).clientdata = new_pure(clientdata), false, 0, ClientData_Send);
171 CS(this).clientdata.drawonlytoclient = this;
172 CS(this).clientdata.owner = this;
175 void ClientData_Detach(entity this)
177 delete(CS(this).clientdata);
178 CS(this).clientdata = NULL;
181 void ClientData_Touch(entity e)
183 entity cd = CS(e).clientdata;
184 if (cd) { cd.SendFlags = 1; }
186 // make it spectatable
187 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != e && IS_SPEC(it) && it.enemy == e,
189 entity cd = CS(it).clientdata;
190 if (cd) { cd.SendFlags = 1; }
199 Checks if the argument string can be a valid playermodel.
200 Returns a valid one in doubt.
203 string FallbackPlayerModel;
204 string CheckPlayerModel(string plyermodel) {
205 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
207 // note: we cannot summon Don Strunzone here, some player may
208 // still have the model string set. In case anyone manages how
209 // to change a cvar default, we'll have a small leak here.
210 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
212 // only in right path
213 if(substring(plyermodel, 0, 14) != "models/player/")
214 return FallbackPlayerModel;
215 // only good file extensions
216 if(substring(plyermodel, -4, 4) != ".iqm"
217 && substring(plyermodel, -4, 4) != ".zym"
218 && substring(plyermodel, -4, 4) != ".dpm"
219 && substring(plyermodel, -4, 4) != ".md3"
220 && substring(plyermodel, -4, 4) != ".psk")
222 return FallbackPlayerModel;
224 // forbid the LOD models
225 if(substring(plyermodel, -9, 5) == "_lod1" || substring(plyermodel, -9, 5) == "_lod2")
226 return FallbackPlayerModel;
227 if(plyermodel != strtolower(plyermodel))
228 return FallbackPlayerModel;
229 // also, restrict to server models
230 if(autocvar_sv_servermodelsonly)
232 if(!fexists(plyermodel))
233 return FallbackPlayerModel;
238 void setplayermodel(entity e, string modelname)
240 precache_model(modelname);
241 _setmodel(e, modelname);
242 player_setupanimsformodel(e);
243 if(!autocvar_g_debug_globalsounds)
244 UpdatePlayerSounds(e);
247 /** putting a client as observer in the server */
248 void PutObserverInServer(entity this, bool is_forced)
250 bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver, this, is_forced);
251 PlayerState_detach(this);
255 if(GetResource(this, RES_HEALTH) >= 1)
258 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
261 // was a player, recount votes and ready status
262 if(IS_REAL_CLIENT(this))
264 if (vote_called) { VoteCount(false); }
267 entcs_update_players(this);
270 entity spot = SelectSpawnPoint(this, true);
271 if (!spot) LOG_FATAL("No spawnpoints for observers?!?");
272 this.angles = vec2(spot.angles);
273 this.fixangle = true;
274 // offset it so that the spectator spawns higher off the ground, looks better this way
275 setorigin(this, spot.origin + STAT(PL_VIEW_OFS, this));
276 if (IS_REAL_CLIENT(this))
279 WriteByte(MSG_ONE, SVC_SETVIEW);
280 WriteEntity(MSG_ONE, this);
282 // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
283 // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
284 if(!autocvar_g_debug_globalsounds)
286 // needed for player sounds
288 FixPlayermodel(this);
290 setmodel(this, MDL_Null);
291 setsize(this, STAT(PL_CROUCH_MIN, this), STAT(PL_CROUCH_MAX, this));
292 this.view_ofs = '0 0 0';
294 RemoveGrapplingHooks(this);
295 Portal_ClearAll(this);
296 Unfreeze(this, false);
297 SetSpectatee(this, NULL);
302 PlayerStats_GameReport_Event_Player(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
306 if (this.vehicle) vehicles_exit(this.vehicle, VHEF_RELEASE);
308 WaypointSprite_PlayerDead(this);
310 if (CS(this).killcount != FRAGS_SPECTATOR && !game_stopped && CHAT_NOSPECTATORS())
311 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CHAT_NOSPECTATORS);
313 accuracy_resend(this);
315 CS(this).spectatortime = time;
317 IL_REMOVE(g_bot_targets, this);
318 this.bot_attack = false;
319 if(this.monster_attack)
320 IL_REMOVE(g_monster_targets, this);
321 this.monster_attack = false;
322 STAT(HUD, this) = HUD_NORMAL;
323 TRANSMUTE(Observer, this);
324 this.iscreature = false;
325 this.teleportable = TELEPORT_SIMPLE;
326 if(this.damagedbycontents)
327 IL_REMOVE(g_damagedbycontents, this);
328 this.damagedbycontents = false;
329 SetResourceExplicit(this, RES_HEALTH, FRAGS_SPECTATOR);
330 SetSpectatee_status(this, etof(this));
331 this.takedamage = DAMAGE_NO;
332 this.solid = SOLID_NOT;
333 set_movetype(this, MOVETYPE_FLY_WORLDONLY); // user preference is controlled by playerprethink
334 this.flags = FL_CLIENT | FL_NOTARGET;
336 SetResourceExplicit(this, RES_ARMOR, autocvar_g_balance_armor_start); // was 666?!
337 this.pauserotarmor_finished = 0;
338 this.pauserothealth_finished = 0;
339 this.pauseregen_finished = 0;
340 this.damageforcescale = 0;
342 this.respawn_flags = 0;
343 this.respawn_time = 0;
344 STAT(RESPAWN_TIME, this) = 0;
348 this.pain_finished = 0;
349 STAT(AIR_FINISHED, this) = 0;
350 //this.dphitcontentsmask = 0;
351 this.dphitcontentsmask = DPCONTENTS_SOLID;
352 if (autocvar_g_playerclip_collisions)
353 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
356 setthink(this, func_null);
358 this.deadflag = DEAD_NO;
360 STAT(REVIVE_PROGRESS, this) = 0;
361 this.revival_time = 0;
362 this.draggable = drag_undraggable;
365 STAT(WEAPONS, this) = '0 0 0';
366 this.drawonlytoclient = this;
370 //this.spawnpoint_targ = NULL; // keep it so they can return to where they were?
372 this.weaponmodel = "";
373 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
375 this.weaponentities[slot] = NULL;
377 this.exteriorweaponentity = NULL;
378 CS(this).killcount = FRAGS_SPECTATOR;
379 this.velocity = '0 0 0';
380 this.avelocity = '0 0 0';
381 this.punchangle = '0 0 0';
382 this.punchvector = '0 0 0';
383 this.oldvelocity = this.velocity;
384 this.event_damage = func_null;
385 this.event_heal = func_null;
387 for(int slot = 0; slot < MAX_AXH; ++slot)
389 entity axh = this.(AuxiliaryXhair[slot]);
390 this.(AuxiliaryXhair[slot]) = NULL;
392 if(axh.owner == this && axh != NULL && !wasfreed(axh))
396 if (mutator_returnvalue)
398 // mutator prevents resetting teams+score
402 SetPlayerTeam(this, -1, TEAM_CHANGE_SPECTATOR);
403 this.frags = FRAGS_SPECTATOR;
406 bot_relinkplayerlist();
408 if (CS(this).just_joined)
409 CS(this).just_joined = false;
412 int player_getspecies(entity this)
414 get_model_parameters(this.model, this.skin);
415 int s = get_model_parameters_species;
416 get_model_parameters(string_null, 0);
417 if (s < 0) return SPECIES_HUMAN;
421 .float model_randomizer;
422 void FixPlayermodel(entity player)
424 string defaultmodel = "";
426 if(autocvar_sv_defaultcharacter)
432 case NUM_TEAM_1: defaultmodel = autocvar_sv_defaultplayermodel_red; defaultskin = autocvar_sv_defaultplayerskin_red; break;
433 case NUM_TEAM_2: defaultmodel = autocvar_sv_defaultplayermodel_blue; defaultskin = autocvar_sv_defaultplayerskin_blue; break;
434 case NUM_TEAM_3: defaultmodel = autocvar_sv_defaultplayermodel_yellow; defaultskin = autocvar_sv_defaultplayerskin_yellow; break;
435 case NUM_TEAM_4: defaultmodel = autocvar_sv_defaultplayermodel_pink; defaultskin = autocvar_sv_defaultplayerskin_pink; break;
439 if(defaultmodel == "")
441 defaultmodel = autocvar_sv_defaultplayermodel;
442 defaultskin = autocvar_sv_defaultplayerskin;
445 int n = tokenize_console(defaultmodel);
448 defaultmodel = argv(floor(n * CS(player).model_randomizer));
449 // However, do NOT randomize if the player-selected model is in the list.
450 for (int i = 0; i < n; ++i)
451 if ((argv(i) == player.playermodel && defaultskin == stof(player.playerskin)) || argv(i) == strcat(player.playermodel, ":", player.playerskin))
452 defaultmodel = argv(i);
455 int i = strstrofs(defaultmodel, ":", 0);
458 defaultskin = stof(substring(defaultmodel, i+1, -1));
459 defaultmodel = substring(defaultmodel, 0, i);
462 if(autocvar_sv_defaultcharacterskin && !defaultskin)
468 case NUM_TEAM_1: defaultskin = autocvar_sv_defaultplayerskin_red; break;
469 case NUM_TEAM_2: defaultskin = autocvar_sv_defaultplayerskin_blue; break;
470 case NUM_TEAM_3: defaultskin = autocvar_sv_defaultplayerskin_yellow; break;
471 case NUM_TEAM_4: defaultskin = autocvar_sv_defaultplayerskin_pink; break;
476 defaultskin = autocvar_sv_defaultplayerskin;
479 MUTATOR_CALLHOOK(FixPlayermodel, defaultmodel, defaultskin, player);
480 defaultmodel = M_ARGV(0, string);
481 defaultskin = M_ARGV(1, int);
485 if(defaultmodel != "")
487 if (defaultmodel != player.model)
489 vector m1 = player.mins;
490 vector m2 = player.maxs;
491 setplayermodel (player, defaultmodel);
492 setsize (player, m1, m2);
496 oldskin = player.skin;
497 player.skin = defaultskin;
499 if (player.playermodel != player.model || player.playermodel == "")
501 player.playermodel = CheckPlayerModel(player.playermodel); // this is never "", so no endless loop
502 vector m1 = player.mins;
503 vector m2 = player.maxs;
504 setplayermodel (player, player.playermodel);
505 setsize (player, m1, m2);
509 if(!autocvar_sv_defaultcharacterskin)
511 oldskin = player.skin;
512 player.skin = stof(player.playerskin);
516 oldskin = player.skin;
517 player.skin = defaultskin;
521 if(chmdl || oldskin != player.skin) // model or skin has changed
523 player.species = player_getspecies(player); // update species
524 if(!autocvar_g_debug_globalsounds)
525 UpdatePlayerSounds(player); // update skin sounds
529 if(strlen(autocvar_sv_defaultplayercolors))
530 if(player.clientcolors != stof(autocvar_sv_defaultplayercolors))
531 setcolor(player, stof(autocvar_sv_defaultplayercolors));
534 void ResetPlayerResources(entity this)
537 SetResource(this, RES_SHELLS, warmup_start_ammo_shells);
538 SetResource(this, RES_BULLETS, warmup_start_ammo_nails);
539 SetResource(this, RES_ROCKETS, warmup_start_ammo_rockets);
540 SetResource(this, RES_CELLS, warmup_start_ammo_cells);
541 SetResource(this, RES_PLASMA, warmup_start_ammo_plasma);
542 SetResource(this, RES_FUEL, warmup_start_ammo_fuel);
543 SetResource(this, RES_HEALTH, warmup_start_health);
544 SetResource(this, RES_ARMOR, warmup_start_armorvalue);
545 STAT(WEAPONS, this) = WARMUP_START_WEAPONS;
547 SetResource(this, RES_SHELLS, start_ammo_shells);
548 SetResource(this, RES_BULLETS, start_ammo_nails);
549 SetResource(this, RES_ROCKETS, start_ammo_rockets);
550 SetResource(this, RES_CELLS, start_ammo_cells);
551 SetResource(this, RES_PLASMA, start_ammo_plasma);
552 SetResource(this, RES_FUEL, start_ammo_fuel);
553 SetResource(this, RES_HEALTH, start_health);
554 SetResource(this, RES_ARMOR, start_armorvalue);
555 STAT(WEAPONS, this) = start_weapons;
556 if (MUTATOR_CALLHOOK(ForbidRandomStartWeapons, this) == false)
558 GiveRandomWeapons(this, random_start_weapons_count,
559 autocvar_g_random_start_weapons, random_start_ammo);
564 void PutPlayerInServer(entity this)
566 if (this.vehicle) vehicles_exit(this.vehicle, VHEF_RELEASE);
568 PlayerState_attach(this);
569 accuracy_resend(this);
572 TeamBalance_JoinBestTeam(this);
574 entity spot = SelectSpawnPoint(this, false);
576 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
577 return; // spawn failed
580 TRANSMUTE(Player, this);
582 CS(this).wasplayer = true;
583 this.iscreature = true;
584 this.teleportable = TELEPORT_NORMAL;
585 if(!this.damagedbycontents)
586 IL_PUSH(g_damagedbycontents, this);
587 this.damagedbycontents = true;
588 set_movetype(this, MOVETYPE_WALK);
589 this.solid = SOLID_SLIDEBOX;
590 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
591 if (autocvar_g_playerclip_collisions)
592 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
593 if (IS_BOT_CLIENT(this) && autocvar_g_botclip_collisions)
594 this.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
595 this.frags = FRAGS_PLAYER;
596 if (INDEPENDENT_PLAYERS) MAKE_INDEPENDENT_PLAYER(this);
597 this.flags = FL_CLIENT | FL_PICKUPITEMS;
598 if (autocvar__notarget)
599 this.flags |= FL_NOTARGET;
600 this.takedamage = DAMAGE_AIM;
601 this.effects = EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
603 ResetPlayerResources(this);
605 SetSpectatee_status(this, 0);
607 PS(this).dual_weapons = '0 0 0';
609 if(STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS)
610 StatusEffects_apply(STATUSEFFECT_Superweapons, this, time + autocvar_g_balance_superweapons_time, 0);
612 this.items = start_items;
614 float shieldtime = time + autocvar_g_spawnshieldtime;
616 this.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
617 this.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
618 this.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
619 this.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
620 if (!sv_ready_restart_after_countdown && time < game_starttime)
622 float f = game_starttime - time;
624 this.pauserotarmor_finished += f;
625 this.pauserothealth_finished += f;
626 this.pauseregen_finished += f;
629 StatusEffects_apply(STATUSEFFECT_SpawnShield, this, shieldtime, 0);
631 this.damageforcescale = autocvar_g_player_damageforcescale;
633 this.respawn_flags = 0;
634 this.respawn_time = 0;
635 STAT(RESPAWN_TIME, this) = 0;
636 this.scale = ((q3compat && autocvar_sv_q3compat_changehitbox) ? 0.9 : autocvar_sv_player_scale);
638 this.pain_finished = 0;
640 setthink(this, func_null); // players have no think function
643 PS(this).ballistics_density = autocvar_g_ballistics_density_player;
645 this.deadflag = DEAD_NO;
647 this.angles = spot.angles;
648 this.angles_z = 0; // never spawn tilted even if the spot says to
649 if (IS_BOT_CLIENT(this))
651 this.v_angle = this.angles;
654 this.fixangle = true; // turn this way immediately
655 this.oldvelocity = this.velocity = '0 0 0';
656 this.avelocity = '0 0 0';
657 this.punchangle = '0 0 0';
658 this.punchvector = '0 0 0';
660 STAT(REVIVE_PROGRESS, this) = 0;
661 this.revival_time = 0;
663 STAT(AIR_FINISHED, this) = 0;
664 this.waterlevel = WATERLEVEL_NONE;
665 this.watertype = CONTENT_EMPTY;
667 entity spawnevent = new_pure(spawnevent);
668 spawnevent.owner = this;
669 Net_LinkEntity(spawnevent, false, 0.5, SpawnEvent_Send);
671 // Cut off any still running player sounds.
672 stopsound(this, CH_PLAYER_SINGLE);
675 FixPlayermodel(this);
676 this.drawonlytoclient = NULL;
680 for(int slot = 0; slot < MAX_AXH; ++slot)
682 entity axh = this.(AuxiliaryXhair[slot]);
683 this.(AuxiliaryXhair[slot]) = NULL;
685 if(axh.owner == this && axh != NULL && !wasfreed(axh))
689 this.spawnpoint_targ = NULL;
692 this.view_ofs = STAT(PL_VIEW_OFS, this);
693 setsize(this, STAT(PL_MIN, this), STAT(PL_MAX, this));
694 this.spawnorigin = spot.origin;
695 setorigin(this, spot.origin + '0 0 1' * (1 - this.mins.z - 24));
696 // don't reset back to last position, even if new position is stuck in solid
697 this.oldorigin = this.origin;
699 IL_REMOVE(g_conveyed, this);
700 this.conveyor = NULL; // prevent conveyors at the previous location from moving a freshly spawned player
702 IL_REMOVE(g_swamped, this);
703 this.swampslug = NULL;
704 this.swamp_interval = 0;
705 if(this.ladder_entity)
706 IL_REMOVE(g_ladderents, this);
707 this.ladder_entity = NULL;
708 IL_EACH(g_counters, it.realowner == this,
712 STAT(HUD, this) = HUD_NORMAL;
714 this.event_damage = PlayerDamage;
715 this.event_heal = PlayerHeal;
717 this.draggable = func_null;
720 IL_PUSH(g_bot_targets, this);
721 this.bot_attack = true;
722 if(!this.monster_attack)
723 IL_PUSH(g_monster_targets, this);
724 this.monster_attack = true;
725 navigation_dynamicgoal_init(this, false);
727 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_JUMP(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
729 // player was spectator
730 if (CS(this).killcount == FRAGS_SPECTATOR) {
731 PlayerScore_Clear(this);
732 CS(this).killcount = 0;
733 CS(this).startplaytime = time;
736 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
738 .entity weaponentity = weaponentities[slot];
739 CL_SpawnWeaponentity(this, weaponentity);
741 this.alpha = default_player_alpha;
742 this.colormod = '1 1 1' * autocvar_g_player_brightness;
743 this.exteriorweaponentity.alpha = default_weapon_alpha;
745 this.speedrunning = false;
747 this.counter_cnt = 0;
748 this.fragsfilter_cnt = 0;
750 target_voicescript_clear(this);
752 // reset fields the weapons may use
753 FOREACH(Weapons, true, {
754 it.wr_resetplayer(it, this);
755 // reload all reloadable weapons
756 if (it.spawnflags & WEP_FLAG_RELOADABLE) {
757 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
759 .entity weaponentity = weaponentities[slot];
760 this.(weaponentity).weapon_load[it.m_id] = it.reloading_ammo;
765 Unfreeze(this, false);
767 MUTATOR_CALLHOOK(PlayerSpawn, this, spot);
770 string s = spot.target;
771 if(g_assault || g_race) // TODO: make targeting work in assault & race without this hack
772 spot.target = string_null;
773 SUB_UseTargets(spot, this, NULL);
774 if(g_assault || g_race)
778 if (autocvar_spawn_debug)
780 sprint(this, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
781 delete(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
784 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
786 .entity weaponentity = weaponentities[slot];
787 entity w_ent = this.(weaponentity);
788 if(slot == 0 || autocvar_g_weaponswitch_debug == 1)
789 w_ent.m_switchweapon = w_getbestweapon(this, weaponentity);
791 w_ent.m_switchweapon = WEP_Null;
792 w_ent.m_weapon = WEP_Null;
793 w_ent.weaponname = "";
794 w_ent.m_switchingweapon = WEP_Null;
798 MUTATOR_CALLHOOK(PlayerWeaponSelect, this);
800 if (CS(this).impulse) ImpulseCommands(this);
802 W_ResetGunAlign(this, CS_CVAR(this).cvar_cl_gunalign);
803 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
805 .entity weaponentity = weaponentities[slot];
806 W_WeaponFrame(this, weaponentity);
809 if (!warmup_stage && !this.alivetime)
810 this.alivetime = time;
812 antilag_clear(this, CS(this));
815 /** Called when a client spawns in the server */
816 void PutClientInServer(entity this)
818 if (IS_BOT_CLIENT(this)) {
819 TRANSMUTE(Player, this);
820 } else if (IS_REAL_CLIENT(this)) {
822 WriteByte(MSG_ONE, SVC_SETVIEW);
823 WriteEntity(MSG_ONE, this);
826 TRANSMUTE(Observer, this);
828 SetSpectatee(this, NULL);
832 PS(this).itemkeys = 0;
834 MUTATOR_CALLHOOK(PutClientInServer, this);
836 if (IS_OBSERVER(this)) {
837 PutObserverInServer(this, false);
838 } else if (IS_PLAYER(this)) {
839 PutPlayerInServer(this);
842 if(teamplay && IS_REAL_CLIENT(this))
843 send_TeamNames(MSG_ONE, this);
844 bot_relinkplayerlist();
847 // TODO do we need all these fields, or should we stop autodetecting runtime
848 // changes and just have a console command to update this?
849 bool ClientInit_SendEntity(entity this, entity to, int sf)
851 WriteHeader(MSG_ENTITY, _ENT_CLIENT_INIT);
854 // MSG_INIT replacement
855 // TODO: make easier to use
857 W_PROP_reload(MSG_ONE, to);
858 ClientInit_misc(this);
859 MUTATOR_CALLHOOK(Ent_Init);
861 void ClientInit_misc(entity this)
863 int channel = MSG_ONE;
864 WriteHeader(channel, ENT_CLIENT_INIT);
865 WriteByte(channel, g_nexball_meter_period * 32);
866 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[0]));
867 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[1]));
868 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[2]));
869 WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[3]));
870 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[0]));
871 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[1]));
872 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[2]));
873 WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[3]));
875 if(autocvar_sv_foginterval && world.fog != "")
876 WriteString(channel, world.fog);
878 WriteString(channel, "");
879 WriteByte(channel, this.count * 255.0); // g_balance_armor_blockpercent
880 WriteByte(channel, this.cnt * 255.0); // g_balance_damagepush_speedfactor
881 WriteByte(channel, serverflags);
882 WriteCoord(channel, autocvar_g_trueaim_minrange);
884 // z411 send full hostname
885 WriteString(channel, (autocvar_hostname_full != "" ? autocvar_hostname_full : autocvar_hostname));
886 WriteString(channel, autocvar_sv_motd_permanent);
889 void ClientInit_CheckUpdate(entity this)
891 this.nextthink = time;
892 if(this.count != autocvar_g_balance_armor_blockpercent)
894 this.count = autocvar_g_balance_armor_blockpercent;
897 if(this.cnt != autocvar_g_balance_damagepush_speedfactor)
899 this.cnt = autocvar_g_balance_damagepush_speedfactor;
904 void ClientInit_Spawn()
906 entity e = new_pure(clientinit);
907 setthink(e, ClientInit_CheckUpdate);
908 Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
910 ClientInit_CheckUpdate(e);
920 // initialize parms for a new player
921 parm1 = -(86400 * 366);
923 MUTATOR_CALLHOOK(SetNewParms);
931 void SetChangeParms (entity this)
933 // save parms for level change
934 parm1 = CS(this).parm_idlesince - time;
936 MUTATOR_CALLHOOK(SetChangeParms);
944 void DecodeLevelParms(entity this)
947 CS(this).parm_idlesince = parm1;
948 if (CS(this).parm_idlesince == -(86400 * 366))
949 CS(this).parm_idlesince = time;
951 // whatever happens, allow 60 seconds of idling directly after connect for map loading
952 CS(this).parm_idlesince = max(CS(this).parm_idlesince, time - autocvar_sv_maxidle + 60);
954 MUTATOR_CALLHOOK(DecodeLevelParms);
957 void FixClientCvars(entity e)
959 // send prediction settings to the client
960 stuffcmd(e, "\nin_bindmap 0 0\n");
961 if(autocvar_g_antilag == 3) // client side hitscan
962 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
963 if(autocvar_sv_gentle)
964 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
966 stuffcmd(e, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
967 stuffcmd(e, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
969 stuffcmd(e, sprintf("\ncl_shootfromfixedorigin \"%s\"\n", autocvar_g_shootfromfixedorigin));
971 MUTATOR_CALLHOOK(FixClientCvars, e);
974 bool findinlist_abbrev(string tofind, string list)
976 if(list == "" || tofind == "")
977 return false; // empty list or search, just return
979 // this function allows abbreviated strings!
980 FOREACH_WORD(list, it == substring(tofind, 0, strlen(it)),
988 bool PlayerInIPList(entity p, string iplist)
990 // some safety checks (never allow local?)
991 if(p.netaddress == "local" || p.netaddress == "" || !IS_REAL_CLIENT(p))
994 return findinlist_abbrev(p.netaddress, iplist);
997 bool PlayerInIDList(entity p, string idlist)
999 // NOTE: we do NOT check crypto_idfp_signed here, an unsigned ID is fine too for this
1003 return findinlist_abbrev(p.crypto_idfp, idlist);
1006 bool PlayerInList(entity player, string list)
1008 return boolean(PlayerInIDList(player, list) || PlayerInIPList(player, list));
1011 #ifdef DP_EXT_PRECONNECT
1016 Called once (not at each match start) when a client begins a connection to the server
1019 void ClientPreConnect(entity this)
1021 if(autocvar_sv_eventlog)
1023 GameLogEcho(sprintf(":connect:%d:%d:%s",
1026 ((IS_REAL_CLIENT(this)) ? this.netaddress : "bot")
1032 string GetClientVersionMessage(entity this)
1034 if (CS(this).version_mismatch) {
1035 if(CS(this).version < autocvar_gameversion) {
1036 return strcat("This is Xonotic ", autocvar_g_xonoticversion,
1037 "\n^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8");
1039 return strcat("This is Xonotic ", autocvar_g_xonoticversion,
1040 "\n^3This server is using an outdated Xonotic version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8");
1043 return strcat("Welcome to Xonotic ", autocvar_g_xonoticversion);
1047 string getwelcomemessage(entity this)
1049 MUTATOR_CALLHOOK(BuildMutatorsPrettyString, "");
1050 string modifications = M_ARGV(0, string);
1054 if(g_weaponarena_random)
1055 modifications = strcat(modifications, ", ", ftos(g_weaponarena_random), " of ", g_weaponarena_list, " Arena");
1057 modifications = strcat(modifications, ", ", g_weaponarena_list, " Arena");
1059 else if(cvar("g_balance_blaster_weaponstartoverride") == 0)
1060 modifications = strcat(modifications, ", No start weapons");
1061 if(cvar("sv_gravity") < stof(cvar_defstring("sv_gravity")))
1062 modifications = strcat(modifications, ", Low gravity");
1063 if(g_weapon_stay && !g_cts)
1064 modifications = strcat(modifications, ", Weapons stay");
1065 if(autocvar_g_jetpack)
1066 modifications = strcat(modifications, ", Jet pack");
1067 modifications = substring(modifications, 2, strlen(modifications) - 2);
1069 //string versionmessage = GetClientVersionMessage(this);
1070 //string s = strcat(versionmessage, "^8\n^9", (autocvar_hostname_full ? autocvar_hostname_full : autocvar_hostname));
1071 //string s = strcat(versionmessage, "^8\n^8\nserver is ^9", autocvar_hostname, "^8\n");
1072 string s = (autocvar_hostname_full != "" ? autocvar_hostname_full : autocvar_hostname);
1074 s = strcat(s, "^8\n^7", gamemode_name);
1076 if(modifications != "")
1077 s = strcat(s, "^7 | ^3", modifications);
1079 if(cache_lastmutatormsg != autocvar_g_mutatormsg)
1081 strcpy(cache_lastmutatormsg, autocvar_g_mutatormsg);
1082 strcpy(cache_mutatormsg, cache_lastmutatormsg);
1085 if (cache_mutatormsg != "") {
1086 s = strcat(s, "\n^8tips: ^7", cache_mutatormsg);
1089 string mutator_msg = "";
1090 MUTATOR_CALLHOOK(BuildGameplayTipsString, mutator_msg);
1091 mutator_msg = M_ARGV(0, string);
1093 s = strcat(s, mutator_msg); // trust that the mutator will do proper formatting
1095 string motd = autocvar_sv_motd;
1097 s = strcat(s, "\n\n^7", strreplace("\\n", "\n", motd));
1106 Called when a client connects to the server
1109 void ClientConnect(entity this)
1111 if (Ban_MaybeEnforceBanOnce(this)) return;
1112 assert(!IS_CLIENT(this), return);
1113 this.flags |= FL_CLIENT;
1114 assert(player_count >= 0, player_count = 0);
1116 TRANSMUTE(Client, this);
1117 CS(this).version_nagtime = time + 10 + random() * 10;
1119 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_JOIN_CONNECT, this.netname);
1121 bot_clientconnect(this);
1123 Player_DetermineForcedTeam(this);
1125 TRANSMUTE(Observer, this);
1127 PlayerStats_GameReport_AddEvent(sprintf("kills-%d", this.playerid));
1129 // always track bots, don't ask for cl_allow_uidtracking
1130 if (IS_BOT_CLIENT(this))
1131 PlayerStats_GameReport_AddPlayer(this);
1133 CS(this).allowed_timeouts = autocvar_sv_timeout_number;
1135 if (autocvar_sv_eventlog)
1136 GameLogEcho(strcat(":join:", ftos(this.playerid), ":", ftos(etof(this)), ":", ((IS_REAL_CLIENT(this)) ? GameLog_ProcessIP(this.netaddress) : "bot"), ":", playername(this.netname, this.team, false)));
1138 CS(this).just_joined = true; // stop spamming the eventlog with additional lines when the client connects
1140 stuffcmd(this, clientstuff, "\n");
1141 stuffcmd(this, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1143 FixClientCvars(this);
1145 // get version info from player
1146 stuffcmd(this, "cmd clientversion $gameversion\n");
1148 // notify about available teams
1151 entity balance = TeamBalance_CheckAllowedTeams(this);
1152 int t = TeamBalance_GetAllowedTeams(balance);
1153 TeamBalance_Destroy(balance);
1154 stuffcmd(this, sprintf("set _teams_available %d\n", t));
1158 stuffcmd(this, "set _teams_available 0\n");
1161 bot_relinkplayerlist();
1163 CS(this).spectatortime = time;
1164 if (blockSpectators)
1166 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1169 CS(this).jointime = time;
1171 if (IS_REAL_CLIENT(this))
1173 if (g_weaponarena_weapons == WEPSET(TUBA))
1174 stuffcmd(this, "cl_cmd settemp chase_active 1\n");
1177 if (!autocvar_sv_foginterval && world.fog != "")
1178 stuffcmd(this, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1180 if (autocvar_sv_teamnagger && !(autocvar_bot_vs_human && AvailableTeams() == 2))
1181 if(!MUTATOR_CALLHOOK(HideTeamNagger, this))
1182 send_CSQC_teamnagger();
1184 CSQCMODEL_AUTOINIT(this);
1186 CS(this).model_randomizer = random();
1188 if (IS_REAL_CLIENT(this))
1189 sv_notice_join(this);
1191 this.move_qcphysics = autocvar_sv_qcphysics;
1193 // update physics stats (players can spawn before physics runs)
1194 Physics_UpdateStats(this);
1196 IL_EACH(g_initforplayer, it.init_for_player, {
1197 it.init_for_player(it, this);
1200 Handicap_Initialize(this);
1202 MUTATOR_CALLHOOK(ClientConnect, this);
1204 if (IS_REAL_CLIENT(this))
1206 if (!autocvar_g_campaign && !IS_PLAYER(this))
1208 CS(this).motd_actived_time = -1;
1209 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage(this));
1217 Called when a client disconnects from the server
1220 .entity chatbubbleentity;
1221 void player_powerups_remove_all(entity this);
1223 void ClientDisconnect(entity this)
1225 assert(IS_CLIENT(this), return);
1227 PlayerStats_GameReport_FinalizePlayer(this);
1228 if (this.vehicle) vehicles_exit(this.vehicle, VHEF_RELEASE);
1229 if (CS(this).active_minigame) part_minigame(this);
1230 if (IS_PLAYER(this)) Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
1232 if (autocvar_sv_eventlog)
1233 GameLogEcho(strcat(":part:", ftos(this.playerid)));
1235 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
1238 SetSpectatee(this, NULL);
1240 MUTATOR_CALLHOOK(ClientDisconnect, this);
1242 strfree(CS(this).netname_previous); // needs to be before the CS entity is removed!
1243 strfree(CS_CVAR(this).weaponorder_byimpulse);
1244 ClientState_detach(this);
1246 Portal_ClearAll(this);
1248 Unfreeze(this, false);
1250 RemoveGrapplingHooks(this);
1252 // Here, everything has been done that requires this player to be a client.
1254 this.flags &= ~FL_CLIENT;
1256 if (this.chatbubbleentity) delete(this.chatbubbleentity);
1257 if (this.killindicator) delete(this.killindicator);
1259 IL_EACH(g_counters, it.realowner == this,
1264 WaypointSprite_PlayerGone(this);
1266 bot_relinkplayerlist();
1268 strfree(this.clientstatus);
1269 if (this.personal) delete(this.personal);
1273 if (vote_called && IS_REAL_CLIENT(this)) VoteCount(false);
1275 player_powerups_remove_all(this); // stop powerup sound
1280 void ChatBubbleThink(entity this)
1282 this.nextthink = time;
1283 if ((this.owner.alpha < 0) || this.owner.chatbubbleentity != this)
1285 if(this.owner) // but why can that ever be NULL?
1286 this.owner.chatbubbleentity = NULL;
1293 if ( !IS_DEAD(this.owner) && IS_PLAYER(this.owner) )
1295 if ( CS(this.owner).active_minigame && PHYS_INPUT_BUTTON_MINIGAME(this.owner) )
1296 this.mdl = "models/sprites/minigame_busy.iqm";
1297 else if (PHYS_INPUT_BUTTON_CHAT(this.owner))
1298 this.mdl = "models/misc/chatbubble.spr";
1301 if ( this.model != this.mdl )
1302 _setmodel(this, this.mdl);
1306 void UpdateChatBubble(entity this)
1310 // spawn a chatbubble entity if needed
1311 if (!this.chatbubbleentity)
1313 this.chatbubbleentity = new(chatbubbleentity);
1314 this.chatbubbleentity.owner = this;
1315 this.chatbubbleentity.exteriormodeltoclient = this;
1316 setthink(this.chatbubbleentity, ChatBubbleThink);
1317 this.chatbubbleentity.nextthink = time;
1318 setmodel(this.chatbubbleentity, MDL_CHAT); // precision set below
1319 //setorigin(this.chatbubbleentity, this.origin + '0 0 15' + this.maxs_z * '0 0 1');
1320 setorigin(this.chatbubbleentity, '0 0 15' + this.maxs_z * '0 0 1');
1321 setattachment(this.chatbubbleentity, this, ""); // sticks to moving player better, also conserves bandwidth
1322 this.chatbubbleentity.mdl = this.chatbubbleentity.model;
1323 //this.chatbubbleentity.model = "";
1324 this.chatbubbleentity.effects = EF_LOWPRECISION;
1328 void calculate_player_respawn_time(entity this)
1330 if(MUTATOR_CALLHOOK(CalculateRespawnTime, this))
1333 float gametype_setting_tmp;
1334 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
1335 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
1336 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
1337 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
1338 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
1339 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
1341 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
1344 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
1345 if(it.team == this.team)
1348 if (sdelay_small_count == 0)
1349 sdelay_small_count = 1;
1350 if (sdelay_large_count == 0)
1351 sdelay_large_count = 1;
1355 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
1358 if (sdelay_small_count == 0)
1360 if (IS_INDEPENDENT_PLAYER(this))
1362 // Players play independently. No point in requiring enemies.
1363 sdelay_small_count = 1;
1367 // Players play AGAINST each other. Enemies required.
1368 sdelay_small_count = 2;
1371 if (sdelay_large_count == 0)
1373 if (IS_INDEPENDENT_PLAYER(this))
1375 // Players play independently. No point in requiring enemies.
1376 sdelay_large_count = 1;
1380 // Players play AGAINST each other. Enemies required.
1381 sdelay_large_count = 2;
1388 if (pcount <= sdelay_small_count)
1389 sdelay = sdelay_small;
1390 else if (pcount >= sdelay_large_count)
1391 sdelay = sdelay_large;
1392 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
1393 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
1396 this.respawn_time = ceil((time + sdelay) / waves) * waves;
1398 this.respawn_time = time + sdelay;
1400 if(sdelay < sdelay_max)
1401 this.respawn_time_max = time + sdelay_max;
1403 this.respawn_time_max = this.respawn_time;
1405 if((sdelay + waves >= 5.0) && (this.respawn_time - time > 1.75))
1406 this.respawn_countdown = 10; // first number to count down from is 10
1408 this.respawn_countdown = -1; // do not count down
1410 if(autocvar_g_forced_respawn)
1411 this.respawn_flags = this.respawn_flags | RESPAWN_FORCE;
1414 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1415 // added to the model skins
1416 /*void UpdateColorModHack()
1419 c = this.clientcolors & 15;
1420 // LordHavoc: only bothering to support white, green, red, yellow, blue
1421 if (!teamplay) this.colormod = '0 0 0';
1422 else if (c == 0) this.colormod = '1.00 1.00 1.00';
1423 else if (c == 3) this.colormod = '0.10 1.73 0.10';
1424 else if (c == 4) this.colormod = '1.73 0.10 0.10';
1425 else if (c == 12) this.colormod = '1.22 1.22 0.10';
1426 else if (c == 13) this.colormod = '0.10 0.10 1.73';
1427 else this.colormod = '1 1 1';
1430 void respawn(entity this)
1432 bool damagedbycontents_prev = this.damagedbycontents;
1435 if(autocvar_g_respawn_ghosts)
1437 this.solid = SOLID_NOT;
1438 this.takedamage = DAMAGE_NO;
1439 this.damagedbycontents = false;
1440 set_movetype(this, MOVETYPE_FLY);
1441 this.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1442 this.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1443 this.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1444 this.alpha = min(this.alpha, autocvar_g_respawn_ghosts_alpha);
1445 Send_Effect(EFFECT_RESPAWN_GHOST, this.origin, '0 0 0', 1);
1446 if(autocvar_g_respawn_ghosts_time > 0)
1447 SUB_SetFade(this, time + autocvar_g_respawn_ghosts_time, autocvar_g_respawn_ghosts_fadetime);
1450 SUB_SetFade (this, time, 1); // fade out the corpse immediately
1454 this.damagedbycontents = damagedbycontents_prev;
1456 this.effects |= EF_NODRAW; // prevent another CopyBody
1457 PutClientInServer(this);
1460 void play_countdown(entity this, float finished, Sound samp)
1463 if(IS_REAL_CLIENT(this))
1464 if(floor(finished - time - frametime) != floor(finished - time))
1465 if(finished - time < 6)
1466 sound (this, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
1469 void player_powerups_remove_all(entity this)
1471 if (this.items & IT_SUPERWEAPON)
1473 // don't play the poweroff sound when the game restarts or the player disconnects
1474 if (time > game_starttime + 1 && IS_CLIENT(this))
1475 sound(this, CH_INFO, SND_POWEROFF, VOL_BASE, ATTEN_NORM);
1476 stopsound(this, CH_TRIGGER_SINGLE); // get rid of the pickup sound
1477 this.items -= (this.items & IT_SUPERWEAPON);
1481 void player_powerups(entity this)
1483 if((this.items & IT_USING_JETPACK) && !IS_DEAD(this) && !game_stopped)
1484 this.modelflags |= MF_ROCKET;
1486 this.modelflags &= ~MF_ROCKET;
1488 this.effects &= ~EF_NODEPTHTEST;
1491 player_powerups_remove_all(this);
1493 if((this.alpha < 0 || IS_DEAD(this)) && !this.vehicle) // don't apply the flags if the player is gibbed
1496 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1497 int items_prev = this.items;
1499 if (!MUTATOR_IS_ENABLED(mutator_instagib))
1501 // NOTE: superweapons are a special case and as such are handled here instead of the status effects system
1502 if (this.items & IT_SUPERWEAPON)
1504 if (!(STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS))
1506 StatusEffects_remove(STATUSEFFECT_Superweapons, this, STATUSEFFECT_REMOVE_NORMAL);
1507 this.items = this.items - (this.items & IT_SUPERWEAPON);
1508 //Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_SUPERWEAPON_LOST, this.netname);
1509 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1511 else if (this.items & IT_UNLIMITED_SUPERWEAPONS)
1513 // don't let them run out
1517 play_countdown(this, StatusEffects_gettime(STATUSEFFECT_Superweapons, this), SND_POWEROFF);
1518 if (time > StatusEffects_gettime(STATUSEFFECT_Superweapons, this))
1520 this.items = this.items - (this.items & IT_SUPERWEAPON);
1521 STAT(WEAPONS, this) &= ~WEPSET_SUPERWEAPONS;
1522 //Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_SUPERWEAPON_BROKEN, this.netname);
1523 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1527 else if(STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS)
1529 if (time < StatusEffects_gettime(STATUSEFFECT_Superweapons, this) || (this.items & IT_UNLIMITED_SUPERWEAPONS))
1531 this.items = this.items | IT_SUPERWEAPON;
1532 if(!(this.items & IT_UNLIMITED_SUPERWEAPONS))
1535 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_SUPERWEAPON_PICKUP, this.netname);
1536 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1541 if(StatusEffects_active(STATUSEFFECT_Superweapons, this))
1542 StatusEffects_remove(STATUSEFFECT_Superweapons, this, STATUSEFFECT_REMOVE_TIMEOUT);
1543 STAT(WEAPONS, this) &= ~WEPSET_SUPERWEAPONS;
1546 else if(StatusEffects_active(STATUSEFFECT_Superweapons, this)) // cheaper to check than to update each frame!
1548 StatusEffects_remove(STATUSEFFECT_Superweapons, this, STATUSEFFECT_REMOVE_CLEAR);
1552 if(autocvar_g_nodepthtestplayers)
1553 this.effects = this.effects | EF_NODEPTHTEST;
1555 if(autocvar_g_fullbrightplayers)
1556 this.effects = this.effects | EF_FULLBRIGHT;
1558 MUTATOR_CALLHOOK(PlayerPowerups, this, items_prev);
1561 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1563 if(current > stable)
1565 else if(current > stable - 0.25) // when close enough, "snap"
1568 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1571 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1573 if(current < stable)
1575 else if(current < stable + 0.25) // when close enough, "snap"
1578 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1581 void RotRegen(entity this, int res, float limit_mod,
1582 float regenstable, float regenfactor, float regenlinear, float regenframetime,
1583 float rotstable, float rotfactor, float rotlinear, float rotframetime)
1585 float old = GetResource(this, res);
1586 float current = old;
1587 if(current > rotstable)
1589 if(rotframetime > 0)
1591 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1592 current = max(rotstable, current - rotlinear * rotframetime);
1595 else if(current < regenstable)
1597 if(regenframetime > 0)
1599 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1600 current = min(regenstable, current + regenlinear * regenframetime);
1604 float limit = GetResourceLimit(this, res) * limit_mod;
1609 SetResource(this, res, current);
1612 void player_regen(entity this)
1614 float max_mod, regen_mod, rot_mod, limit_mod;
1615 max_mod = regen_mod = rot_mod = limit_mod = 1;
1617 float regen_health = autocvar_g_balance_health_regen;
1618 float regen_health_linear = autocvar_g_balance_health_regenlinear;
1619 float regen_health_rot = autocvar_g_balance_health_rot;
1620 float regen_health_rotlinear = autocvar_g_balance_health_rotlinear;
1621 float regen_health_stable = autocvar_g_balance_health_regenstable;
1622 float regen_health_rotstable = autocvar_g_balance_health_rotstable;
1623 bool mutator_returnvalue = MUTATOR_CALLHOOK(PlayerRegen, this, max_mod, regen_mod, rot_mod, limit_mod, regen_health, regen_health_linear, regen_health_rot,
1624 regen_health_rotlinear, regen_health_stable, regen_health_rotstable);
1625 max_mod = M_ARGV(1, float);
1626 regen_mod = M_ARGV(2, float);
1627 rot_mod = M_ARGV(3, float);
1628 limit_mod = M_ARGV(4, float);
1629 regen_health = M_ARGV(5, float);
1630 regen_health_linear = M_ARGV(6, float);
1631 regen_health_rot = M_ARGV(7, float);
1632 regen_health_rotlinear = M_ARGV(8, float);
1633 regen_health_stable = M_ARGV(9, float);
1634 regen_health_rotstable = M_ARGV(10, float);
1636 float rotstable, regenstable, rotframetime, regenframetime;
1638 if(!mutator_returnvalue)
1639 if(!STAT(FROZEN, this))
1641 regenstable = autocvar_g_balance_armor_regenstable;
1642 rotstable = autocvar_g_balance_armor_rotstable;
1643 regenframetime = (time > this.pauseregen_finished) ? (regen_mod * frametime) : 0;
1644 rotframetime = (time > this.pauserotarmor_finished) ? (rot_mod * frametime) : 0;
1645 RotRegen(this, RES_ARMOR, limit_mod,
1646 regenstable, autocvar_g_balance_armor_regen, autocvar_g_balance_armor_regenlinear, regenframetime,
1647 rotstable, autocvar_g_balance_armor_rot, autocvar_g_balance_armor_rotlinear, rotframetime);
1649 // NOTE: max_mod is only applied to health
1650 regenstable = regen_health_stable * max_mod;
1651 rotstable = regen_health_rotstable * max_mod;
1652 regenframetime = (time > this.pauseregen_finished) ? (regen_mod * frametime) : 0;
1653 rotframetime = (time > this.pauserothealth_finished) ? (rot_mod * frametime) : 0;
1654 RotRegen(this, RES_HEALTH, limit_mod,
1655 regenstable, regen_health, regen_health_linear, regenframetime,
1656 rotstable, regen_health_rot, regen_health_rotlinear, rotframetime);
1659 // if player rotted to death... die!
1660 // check this outside above checks, as player may still be able to rot to death
1661 if(GetResource(this, RES_HEALTH) < 1)
1664 vehicles_exit(this.vehicle, VHEF_RELEASE);
1665 if(this.event_damage)
1666 this.event_damage(this, this, this, 1, DEATH_ROT.m_id, DMG_NOWEP, this.origin, '0 0 0');
1669 if (!(this.items & IT_UNLIMITED_AMMO))
1671 regenstable = autocvar_g_balance_fuel_regenstable;
1672 rotstable = autocvar_g_balance_fuel_rotstable;
1673 regenframetime = ((time > this.pauseregen_finished) && (this.items & ITEM_JetpackRegen.m_itemid)) ? frametime : 0;
1674 rotframetime = (time > this.pauserotfuel_finished) ? frametime : 0;
1675 RotRegen(this, RES_FUEL, 1,
1676 regenstable, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, regenframetime,
1677 rotstable, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, rotframetime);
1682 void SetZoomState(entity this, float newzoom)
1684 if(newzoom != CS(this).zoomstate)
1686 CS(this).zoomstate = newzoom;
1687 ClientData_Touch(this);
1689 zoomstate_set = true;
1692 void GetPressedKeys(entity this)
1694 MUTATOR_CALLHOOK(GetPressedKeys, this);
1697 CS(this).pressedkeys = 0;
1698 STAT(PRESSED_KEYS, this) = 0;
1702 // NOTE: GetPressedKeys and PM_dodging_GetPressedKeys use similar code
1703 int keys = STAT(PRESSED_KEYS, this);
1704 keys = BITSET(keys, KEY_FORWARD, CS(this).movement.x > 0);
1705 keys = BITSET(keys, KEY_BACKWARD, CS(this).movement.x < 0);
1706 keys = BITSET(keys, KEY_RIGHT, CS(this).movement.y > 0);
1707 keys = BITSET(keys, KEY_LEFT, CS(this).movement.y < 0);
1709 keys = BITSET(keys, KEY_JUMP, PHYS_INPUT_BUTTON_JUMP(this));
1710 keys = BITSET(keys, KEY_CROUCH, IS_DUCKED(this)); // workaround: player can't un-crouch until their path is clear, so we keep the button held here
1711 keys = BITSET(keys, KEY_ATCK, PHYS_INPUT_BUTTON_ATCK(this));
1712 keys = BITSET(keys, KEY_ATCK2, PHYS_INPUT_BUTTON_ATCK2(this));
1713 CS(this).pressedkeys = keys; // store for other users
1715 STAT(PRESSED_KEYS, this) = keys;
1719 ======================
1720 spectate mode routines
1721 ======================
1724 void SpectateCopy(entity this, entity spectatee)
1726 TC(Client, this); TC(Client, spectatee);
1728 MUTATOR_CALLHOOK(SpectateCopy, spectatee, this);
1729 PS(this) = PS(spectatee);
1730 this.armortype = spectatee.armortype;
1731 SetResourceExplicit(this, RES_ARMOR, GetResource(spectatee, RES_ARMOR));
1732 SetResourceExplicit(this, RES_CELLS, GetResource(spectatee, RES_CELLS));
1733 SetResourceExplicit(this, RES_PLASMA, GetResource(spectatee, RES_PLASMA));
1734 SetResourceExplicit(this, RES_SHELLS, GetResource(spectatee, RES_SHELLS));
1735 SetResourceExplicit(this, RES_BULLETS, GetResource(spectatee, RES_BULLETS));
1736 SetResourceExplicit(this, RES_ROCKETS, GetResource(spectatee, RES_ROCKETS));
1737 SetResourceExplicit(this, RES_FUEL, GetResource(spectatee, RES_FUEL));
1738 this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1739 SetResourceExplicit(this, RES_HEALTH, GetResource(spectatee, RES_HEALTH));
1740 CS(this).impulse = 0;
1741 this.disableclientprediction = 1; // no need to run prediction on a spectator
1742 this.items = spectatee.items;
1743 STAT(LAST_PICKUP, this) = STAT(LAST_PICKUP, spectatee);
1744 STAT(HIT_TIME, this) = STAT(HIT_TIME, spectatee);
1745 STAT(AIR_FINISHED, this) = STAT(AIR_FINISHED, spectatee);
1746 STAT(PRESSED_KEYS, this) = STAT(PRESSED_KEYS, spectatee);
1747 STAT(WEAPONS, this) = STAT(WEAPONS, spectatee);
1748 this.punchangle = spectatee.punchangle;
1749 this.view_ofs = spectatee.view_ofs;
1750 this.velocity = spectatee.velocity;
1751 this.dmg_take = spectatee.dmg_take;
1752 this.dmg_save = spectatee.dmg_save;
1753 this.dmg_inflictor = spectatee.dmg_inflictor;
1754 this.v_angle = spectatee.v_angle;
1755 this.angles = spectatee.v_angle;
1756 STAT(FROZEN, this) = STAT(FROZEN, spectatee);
1757 STAT(REVIVE_PROGRESS, this) = STAT(REVIVE_PROGRESS, spectatee);
1758 this.viewloc = spectatee.viewloc;
1759 if(!PHYS_INPUT_BUTTON_USE(this) && STAT(CAMERA_SPECTATOR, this) != 2)
1760 this.fixangle = true;
1761 setorigin(this, spectatee.origin);
1762 setsize(this, spectatee.mins, spectatee.maxs);
1763 SetZoomState(this, CS(spectatee).zoomstate);
1765 anticheat_spectatecopy(this, spectatee);
1766 STAT(HUD, this) = STAT(HUD, spectatee);
1767 if(spectatee.vehicle)
1769 this.angles = spectatee.v_angle;
1771 //this.fixangle = false;
1772 //this.velocity = spectatee.vehicle.velocity;
1773 this.vehicle_health = spectatee.vehicle_health;
1774 this.vehicle_shield = spectatee.vehicle_shield;
1775 this.vehicle_energy = spectatee.vehicle_energy;
1776 this.vehicle_ammo1 = spectatee.vehicle_ammo1;
1777 this.vehicle_ammo2 = spectatee.vehicle_ammo2;
1778 this.vehicle_reload1 = spectatee.vehicle_reload1;
1779 this.vehicle_reload2 = spectatee.vehicle_reload2;
1781 //msg_entity = this;
1783 // WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1784 //WriteAngle(MSG_ONE, spectatee.v_angle.x);
1785 // WriteAngle(MSG_ONE, spectatee.v_angle.y);
1786 // WriteAngle(MSG_ONE, spectatee.v_angle.z);
1788 //WriteByte (MSG_ONE, SVC_SETVIEW);
1789 // WriteEntity(MSG_ONE, this);
1790 //makevectors(spectatee.v_angle);
1791 //setorigin(this, spectatee.origin - v_forward * 400 + v_up * 300);*/
1795 bool SpectateUpdate(entity this)
1800 if(!IS_PLAYER(this.enemy) || this == this.enemy)
1802 SetSpectatee(this, NULL);
1806 SpectateCopy(this, this.enemy);
1811 bool SpectateSet(entity this)
1813 if(!IS_PLAYER(this.enemy))
1816 ClientData_Touch(this.enemy);
1819 WriteByte(MSG_ONE, SVC_SETVIEW);
1820 WriteEntity(MSG_ONE, this.enemy);
1821 set_movetype(this, MOVETYPE_NONE);
1822 accuracy_resend(this);
1824 if(!SpectateUpdate(this))
1825 PutObserverInServer(this, false);
1830 void SetSpectatee_status(entity this, int spectatee_num)
1832 int oldspectatee_status = CS(this).spectatee_status;
1833 CS(this).spectatee_status = spectatee_num;
1835 if (CS(this).spectatee_status != oldspectatee_status)
1837 if (STAT(PRESSED_KEYS, this))
1839 CS(this).pressedkeys = 0;
1840 STAT(PRESSED_KEYS, this) = 0;
1842 ClientData_Touch(this);
1843 if (g_race || g_cts) race_InitSpectator();
1847 void SetSpectatee(entity this, entity spectatee)
1849 if(IS_BOT_CLIENT(this))
1850 return; // bots abuse .enemy, this code is useless to them
1852 entity old_spectatee = this.enemy;
1854 this.enemy = spectatee;
1857 // these are required to fix the spectator bug with arc
1860 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1862 .entity weaponentity = weaponentities[slot];
1863 if(old_spectatee.(weaponentity).arc_beam)
1864 old_spectatee.(weaponentity).arc_beam.SendFlags |= ARC_SF_SETTINGS;
1869 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1871 .entity weaponentity = weaponentities[slot];
1872 if(this.enemy.(weaponentity).arc_beam)
1873 this.enemy.(weaponentity).arc_beam.SendFlags |= ARC_SF_SETTINGS;
1878 SetSpectatee_status(this, etof(this.enemy));
1880 // needed to update spectator list
1881 if(old_spectatee) { ClientData_Touch(old_spectatee); }
1884 bool Spectate(entity this, entity pl)
1886 if(MUTATOR_CALLHOOK(SpectateSet, this, pl))
1888 pl = M_ARGV(1, entity);
1890 SetSpectatee(this, pl);
1891 return SpectateSet(this);
1894 bool SpectateNext(entity this)
1896 entity ent = find(this.enemy, classname, STR_PLAYER);
1898 if (MUTATOR_CALLHOOK(SpectateNext, this, ent))
1899 ent = M_ARGV(1, entity);
1901 ent = find(ent, classname, STR_PLAYER);
1903 if(ent) { SetSpectatee(this, ent); }
1905 return SpectateSet(this);
1908 bool SpectatePrev(entity this)
1910 // NOTE: chain order is from the highest to the lower entnum (unlike find)
1911 entity ent = findchain(classname, STR_PLAYER);
1912 if (!ent) // no player
1916 // skip players until current spectated player
1918 while(ent && ent != this.enemy)
1921 switch (MUTATOR_CALLHOOK(SpectatePrev, this, ent, first))
1923 case MUT_SPECPREV_FOUND:
1924 ent = M_ARGV(1, entity);
1926 case MUT_SPECPREV_RETURN:
1928 case MUT_SPECPREV_CONTINUE:
1939 SetSpectatee(this, ent);
1940 return SpectateSet(this);
1945 ShowRespawnCountdown()
1947 Update a respawn countdown display.
1950 void ShowRespawnCountdown(entity this)
1953 if(!IS_DEAD(this)) // just respawned?
1957 number = ceil(this.respawn_time - time);
1960 if(number <= this.respawn_countdown)
1962 this.respawn_countdown = number - 1;
1963 if(ceil(this.respawn_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
1964 { Send_Notification(NOTIF_ONE, this, MSG_ANNCE, Announcer_PickNumber(CNT_RESPAWN, number)); }
1969 .bool team_selected;
1970 bool ShowTeamSelection(entity this)
1972 if (!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || this.team_selected || (CS(this).wasplayer && autocvar_g_changeteam_banned) || Player_HasRealForcedTeam(this))
1974 stuffcmd(this, "menu_showteamselect\n");
1977 void Join(entity this)
1979 TRANSMUTE(Player, this);
1981 if(!this.team_selected)
1982 if(autocvar_g_campaign || autocvar_g_balance_teams)
1983 TeamBalance_JoinBestTeam(this);
1985 if(autocvar_g_campaign)
1986 campaign_bots_may_start = true;
1988 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_PREVENT_JOIN);
1990 PutClientInServer(this);
1993 if(teamplay && this.team != -1)
1997 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_JOIN_PLAY, this.netname);
1998 this.team_selected = false;
2001 // send constant ready notification
2003 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MISSING_READY);
2006 int GetPlayerLimit()
2009 return 2; // TODO: this workaround is needed since the mutator hook from duel can't be activated before the gametype is loaded (e.g. switching modes via gametype vote screen)
2010 int player_limit = autocvar_g_maxplayers;
2011 MUTATOR_CALLHOOK(GetPlayerLimit, player_limit);
2012 player_limit = M_ARGV(0, int);
2013 return player_limit;
2017 * Determines whether the player is allowed to join. This depends on cvar
2018 * g_maxplayers, if it isn't used this function always return true, otherwise
2019 * it checks whether the number of currently playing players exceeds g_maxplayers.
2020 * @return int number of free slots for players, 0 if none
2022 int nJoinAllowed(entity this, entity ignore)
2025 // this is called that way when checking if anyone may be able to join (to build qcstatus)
2026 // so report 0 free slots if restricted
2028 if(autocvar_g_forced_team_otherwise == "spectate")
2030 if(autocvar_g_forced_team_otherwise == "spectator")
2034 if(this && (Player_GetForcedTeamIndex(this) == TEAM_FORCE_SPECTATOR))
2035 return 0; // forced spectators can never join
2037 // TODO simplify this
2038 int totalClients = 0;
2039 int currentlyPlaying = 0;
2040 FOREACH_CLIENT(true, {
2043 if(IS_REAL_CLIENT(it) && (IS_PLAYER(it) || INGAME(it)))
2047 int player_limit = GetPlayerLimit();
2051 free_slots = maxclients - totalClients;
2052 else if(player_limit > 0 && currentlyPlaying < player_limit)
2053 free_slots = min(maxclients - totalClients, player_limit - currentlyPlaying);
2055 static float msg_time = 0;
2056 if(this && !INGAME(this) && ignore && !free_slots && time > msg_time)
2058 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_PREVENT);
2059 msg_time = time + 0.5;
2065 void PrintWelcomeMessage(entity this)
2067 if(CS(this).motd_actived_time == 0)
2069 if (autocvar_g_campaign) {
2070 if ((IS_PLAYER(this) && PHYS_INPUT_BUTTON_INFO(this)) || (!IS_PLAYER(this))) {
2071 CS(this).motd_actived_time = time;
2072 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_CAMPAIGN_MESSAGE, Campaign_GetMessage(), Campaign_GetLevelNum());
2075 if (PHYS_INPUT_BUTTON_INFO(this)) {
2076 CS(this).motd_actived_time = time;
2077 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOTD, getwelcomemessage(this));
2081 else if(CS(this).motd_actived_time > 0) // showing MOTD or campaign message
2083 if (autocvar_g_campaign) {
2084 if (PHYS_INPUT_BUTTON_INFO(this))
2085 CS(this).motd_actived_time = time;
2086 else if ((time - CS(this).motd_actived_time > 2) && IS_PLAYER(this)) { // hide it some seconds after BUTTON_INFO has been released
2087 CS(this).motd_actived_time = 0;
2088 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_CAMPAIGN_MESSAGE);
2091 if (PHYS_INPUT_BUTTON_INFO(this))
2092 CS(this).motd_actived_time = time;
2093 else if (time - CS(this).motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
2094 CS(this).motd_actived_time = 0;
2095 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
2099 else //if(CS(this).motd_actived_time < 0) // just connected, motd is active
2101 if(PHYS_INPUT_BUTTON_INFO(this)) // BUTTON_INFO hides initial MOTD
2102 CS(this).motd_actived_time = -2; // wait until BUTTON_INFO gets released
2103 else if (CS(this).motd_actived_time == -2)
2105 // instantly hide MOTD
2106 CS(this).motd_actived_time = 0;
2107 if (autocvar_g_campaign)
2108 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_CAMPAIGN_MESSAGE);
2110 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_MOTD);
2112 else if (IS_PLAYER(this) || IS_SPEC(this))
2114 // FIXME occasionally for some reason MOTD never goes away
2115 // delay MOTD removal a little bit in the hope it fixes this bug
2116 if (CS(this).motd_actived_time == -1) // MOTD marked to fade away as soon as client becomes player or spectator
2117 CS(this).motd_actived_time = -(5 + floor(random() * 10)); // add small delay
2118 else //if (CS(this).motd_actived_time < -2)
2119 CS(this).motd_actived_time++;
2124 bool joinAllowed(entity this)
2126 if (CS(this).version_mismatch) return false;
2127 if (time < CS(this).jointime + MIN_SPEC_TIME) return false;
2128 if (!nJoinAllowed(this, this)) return false;
2129 if (teamplay && lockteams) return false;
2130 if (MUTATOR_CALLHOOK(ForbidSpawn, this)) return false;
2131 if (ShowTeamSelection(this)) return false;
2135 .string shootfromfixedorigin;
2136 .bool dualwielding_prev;
2137 bool PlayerThink(entity this)
2139 if (game_stopped || intermission_running) {
2140 this.modelflags &= ~MF_ROCKET;
2141 if(intermission_running)
2142 IntermissionThink(this);
2147 // don't allow the player to turn around while game is paused
2148 // FIXME turn this into CSQC stuff
2149 this.v_angle = this.lastV_angle;
2150 this.angles = this.lastV_angle;
2151 this.fixangle = true;
2155 if (frametime) player_powerups(this);
2157 if (IS_DEAD(this)) {
2158 if (this.personal && g_race_qualifying) {
2159 if (time > this.respawn_time) {
2160 STAT(RESPAWN_TIME, this) = this.respawn_time = time + 1; // only retry once a second
2162 CS(this).impulse = CHIMPULSE_SPEEDRUN.impulse;
2165 if (frametime) player_anim(this);
2167 if (this.respawn_flags & RESPAWN_DENY)
2169 STAT(RESPAWN_TIME, this) = 0;
2173 bool button_pressed = (PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_ATCK2(this) || PHYS_INPUT_BUTTON_HOOK(this) || PHYS_INPUT_BUTTON_USE(this));
2175 switch(this.deadflag)
2179 if ((this.respawn_flags & RESPAWN_FORCE) && !(this.respawn_time < this.respawn_time_max))
2180 this.deadflag = DEAD_RESPAWNING;
2181 else if (!button_pressed || (time >= this.respawn_time_max && (this.respawn_flags & RESPAWN_FORCE)))
2182 this.deadflag = DEAD_DEAD;
2188 this.deadflag = DEAD_RESPAWNABLE;
2189 else if (time >= this.respawn_time_max && (this.respawn_flags & RESPAWN_FORCE))
2190 this.deadflag = DEAD_RESPAWNING;
2193 case DEAD_RESPAWNABLE:
2195 if (!button_pressed || (this.respawn_flags & RESPAWN_FORCE))
2196 this.deadflag = DEAD_RESPAWNING;
2199 case DEAD_RESPAWNING:
2201 if (time > this.respawn_time)
2203 this.respawn_time = time + 1; // only retry once a second
2204 this.respawn_time_max = this.respawn_time;
2211 ShowRespawnCountdown(this);
2213 if (this.respawn_flags & RESPAWN_SILENT)
2214 STAT(RESPAWN_TIME, this) = 0;
2215 else if ((this.respawn_flags & RESPAWN_FORCE) && this.respawn_time < this.respawn_time_max)
2217 if (time < this.respawn_time)
2218 STAT(RESPAWN_TIME, this) = this.respawn_time;
2219 else if (this.deadflag != DEAD_RESPAWNING)
2220 STAT(RESPAWN_TIME, this) = -this.respawn_time_max;
2223 STAT(RESPAWN_TIME, this) = this.respawn_time;
2226 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2227 if (this.deadflag == DEAD_RESPAWNING && STAT(RESPAWN_TIME, this) > 0)
2228 STAT(RESPAWN_TIME, this) *= -1;
2233 FixPlayermodel(this);
2235 if (this.shootfromfixedorigin != autocvar_g_shootfromfixedorigin) {
2236 this.shootfromfixedorigin = autocvar_g_shootfromfixedorigin;
2237 stuffcmd(this, sprintf("\ncl_shootfromfixedorigin \"%s\"\n", autocvar_g_shootfromfixedorigin));
2240 // reset gun alignment when dual wielding status changes
2241 // to ensure guns are always aligned right and left
2242 bool dualwielding = W_DualWielding(this);
2243 if(this.dualwielding_prev != dualwielding)
2245 W_ResetGunAlign(this, CS_CVAR(this).cvar_cl_gunalign);
2246 this.dualwielding_prev = dualwielding;
2249 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2252 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
2254 .entity weaponentity = weaponentities[slot];
2255 if(WEP_CVAR(vortex, charge_always))
2256 W_Vortex_Charge(this, weaponentity, frametime);
2257 W_WeaponFrame(this, weaponentity);
2263 // WEAPONTODO: Add a weapon request for this
2264 // rot vortex charge to the charge limit
2265 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
2267 .entity weaponentity = weaponentities[slot];
2268 if (WEP_CVAR(vortex, charge_rot_rate) && this.(weaponentity).vortex_charge > WEP_CVAR(vortex, charge_limit) && this.(weaponentity).vortex_charge_rottime < time)
2269 this.(weaponentity).vortex_charge = bound(WEP_CVAR(vortex, charge_limit), this.(weaponentity).vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1);
2274 this.dmg_team = max(0, this.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2277 monsters_setstatus(this);
2282 .bool would_spectate;
2283 // merged SpectatorThink and ObserverThink (old names are here so you can grep for them)
2284 void ObserverOrSpectatorThink(entity this)
2286 bool is_spec = IS_SPEC(this);
2287 if ( CS(this).impulse )
2289 int r = MinigameImpulse(this, CS(this).impulse);
2291 CS(this).impulse = 0;
2293 if (is_spec && CS(this).impulse == IMP_weapon_drop.impulse)
2295 STAT(CAMERA_SPECTATOR, this) = (STAT(CAMERA_SPECTATOR, this) + 1) % 3;
2296 CS(this).impulse = 0;
2301 if (this.flags & FL_JUMPRELEASED) {
2302 if (PHYS_INPUT_BUTTON_JUMP(this) && (joinAllowed(this) || time < CS(this).jointime + MIN_SPEC_TIME)) {
2303 this.flags &= ~FL_JUMPRELEASED;
2304 this.flags |= FL_SPAWNING;
2305 } else if((is_spec && (PHYS_INPUT_BUTTON_ATCK(this) || CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18 || (CS(this).impulse >= 200 && CS(this).impulse <= 209)))
2306 || (!is_spec && ((PHYS_INPUT_BUTTON_ATCK(this) && !CS(this).version_mismatch) || this.would_spectate))) {
2307 this.flags &= ~FL_JUMPRELEASED;
2308 if(SpectateNext(this)) {
2309 TRANSMUTE(Spectator, this);
2310 } else if (is_spec) {
2311 TRANSMUTE(Observer, this);
2312 PutClientInServer(this);
2315 this.would_spectate = false; // unable to spectate anyone
2317 CS(this).impulse = 0;
2318 } else if (is_spec) {
2319 if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19 || (CS(this).impulse >= 220 && CS(this).impulse <= 229)) {
2320 this.flags &= ~FL_JUMPRELEASED;
2321 if(SpectatePrev(this)) {
2322 TRANSMUTE(Spectator, this);
2324 TRANSMUTE(Observer, this);
2325 PutClientInServer(this);
2327 CS(this).impulse = 0;
2328 } else if(PHYS_INPUT_BUTTON_ATCK2(this)) {
2329 this.would_spectate = false;
2330 this.flags &= ~FL_JUMPRELEASED;
2331 TRANSMUTE(Observer, this);
2332 PutClientInServer(this);
2333 } else if(!SpectateUpdate(this) && !SpectateNext(this)) {
2334 PutObserverInServer(this, false);
2335 this.would_spectate = true;
2339 bool wouldclip = CS_CVAR(this).cvar_cl_clippedspectating;
2340 if (PHYS_INPUT_BUTTON_USE(this))
2341 wouldclip = !wouldclip;
2342 int preferred_movetype = (wouldclip ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
2343 set_movetype(this, preferred_movetype);
2345 } else { // jump pressed
2346 if ((is_spec && !(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this)))
2347 || (!is_spec && !(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_JUMP(this)))) {
2348 this.flags |= FL_JUMPRELEASED;
2349 if(this.flags & FL_SPAWNING)
2351 this.flags &= ~FL_SPAWNING;
2352 if(joinAllowed(this))
2354 else if(time < CS(this).jointime + MIN_SPEC_TIME)
2355 CS(this).autojoin_checked = -1;
2359 if(is_spec && !SpectateUpdate(this))
2360 PutObserverInServer(this, false);
2363 this.flags |= FL_CLIENT | FL_NOTARGET;
2366 void PlayerUseKey(entity this)
2368 if (!IS_PLAYER(this))
2375 vehicles_exit(this.vehicle, VHEF_NORMAL);
2379 else if(autocvar_g_vehicles_enter)
2381 if(!game_stopped && !STAT(FROZEN, this) && !IS_DEAD(this) && !IS_INDEPENDENT_PLAYER(this))
2383 entity head, closest_target = NULL;
2384 head = WarpZone_FindRadius(this.origin, autocvar_g_vehicles_enter_radius, true);
2386 while(head) // find the closest acceptable target to enter
2388 if(IS_VEHICLE(head) && !IS_DEAD(head) && head.takedamage != DAMAGE_NO)
2389 if(!head.owner || ((head.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(head.owner, this)))
2393 if(vlen2(this.origin - head.origin) < vlen2(this.origin - closest_target.origin))
2394 { closest_target = head; }
2396 else { closest_target = head; }
2402 if(closest_target) { vehicles_enter(this, closest_target); return; }
2406 // a use key was pressed; call handlers
2407 MUTATOR_CALLHOOK(PlayerUseKey, this);
2415 Called every frame for each client before the physics are run
2418 .float last_vehiclecheck;
2419 void PlayerPreThink (entity this)
2421 STAT(GUNALIGN, this) = CS_CVAR(this).cvar_cl_gunalign; // TODO
2422 STAT(MOVEVARS_CL_TRACK_CANJUMP, this) = CS_CVAR(this).cvar_cl_movement_track_canjump;
2424 WarpZone_PlayerPhysics_FixVAngle(this);
2427 // physics frames: update anticheat stuff
2428 anticheat_prethink(this);
2430 // WORKAROUND: only use dropclient in server frames (frametime set).
2431 // Never use it in cl_movement frames (frametime zero).
2432 if (blockSpectators && IS_REAL_CLIENT(this)
2433 && (IS_SPEC(this) || IS_OBSERVER(this)) && !INGAME(this)
2434 && time > (CS(this).spectatortime + autocvar_g_maxplayers_spectator_blocktime))
2436 if (dropclient_schedule(this))
2437 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
2441 zoomstate_set = false;
2443 // Check for nameless players
2444 if (this.netname == "" || this.netname != CS(this).netname_previous)
2446 bool assume_unchanged = (CS(this).netname_previous == "");
2447 if (autocvar_sv_name_maxlength > 0 && strlennocol(this.netname) > autocvar_sv_name_maxlength)
2449 int new_length = textLengthUpToLength(this.netname, autocvar_sv_name_maxlength, strlennocol);
2450 this.netname = strzone(strcat(substring(this.netname, 0, new_length), "^7"));
2451 sprint(this, sprintf("Warning: your name is longer than %d characters, it has been truncated.\n", autocvar_sv_name_maxlength));
2452 assume_unchanged = false;
2453 // stuffcmd(this, strcat("name ", this.netname, "\n")); // maybe?
2455 if (isInvisibleString(this.netname))
2457 this.netname = strzone(sprintf("Player#%d", this.playerid));
2458 sprint(this, "Warning: invisible names are not allowed.\n");
2459 assume_unchanged = false;
2460 // stuffcmd(this, strcat("name ", this.netname, "\n")); // maybe?
2462 if (!assume_unchanged && autocvar_sv_eventlog)
2463 GameLogEcho(strcat(":name:", ftos(this.playerid), ":", playername(this.netname, this.team, false)));
2464 strcpy(CS(this).netname_previous, this.netname);
2468 if (CS(this).version_nagtime && CS_CVAR(this).cvar_g_xonoticversion && time > CS(this).version_nagtime) {
2469 CS(this).version_nagtime = 0;
2470 if (strstrofs(CS_CVAR(this).cvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(CS_CVAR(this).cvar_g_xonoticversion, "autobuild", 0) >= 0) {
2472 } else if (strstrofs(autocvar_g_xonoticversion, "git", 0) >= 0 || strstrofs(autocvar_g_xonoticversion, "autobuild", 0) >= 0) {
2474 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, CS_CVAR(this).cvar_g_xonoticversion);
2476 int r = vercmp(CS_CVAR(this).cvar_g_xonoticversion, autocvar_g_xonoticversion);
2477 if (r < 0) { // old client
2478 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, CS_CVAR(this).cvar_g_xonoticversion);
2479 } else if (r > 0) { // old server
2480 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, CS_CVAR(this).cvar_g_xonoticversion);
2486 if (!(this.flags & FL_GODMODE) && this.max_armorvalue)
2488 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_GODMODE_OFF, this.max_armorvalue);
2489 this.max_armorvalue = 0;
2492 if (frametime && IS_PLAYER(this) && time >= game_starttime)
2494 if (STAT(FROZEN, this) == FROZEN_TEMP_REVIVING)
2496 STAT(REVIVE_PROGRESS, this) = bound(0, STAT(REVIVE_PROGRESS, this) + frametime * this.revive_speed, 1);
2497 SetResourceExplicit(this, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, this) * start_health));
2499 this.iceblock.alpha = bound(0.2, 1 - STAT(REVIVE_PROGRESS, this), 1);
2501 if (STAT(REVIVE_PROGRESS, this) >= 1)
2502 Unfreeze(this, false);
2504 else if (STAT(FROZEN, this) == FROZEN_TEMP_DYING)
2506 STAT(REVIVE_PROGRESS, this) = bound(0, STAT(REVIVE_PROGRESS, this) - frametime * this.revive_speed, 1);
2507 SetResourceExplicit(this, RES_HEALTH, max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * STAT(REVIVE_PROGRESS, this)));
2509 if (GetResource(this, RES_HEALTH) < 1)
2512 vehicles_exit(this.vehicle, VHEF_RELEASE);
2513 if(this.event_damage)
2514 this.event_damage(this, this, this.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, DMG_NOWEP, this.origin, '0 0 0');
2516 else if (STAT(REVIVE_PROGRESS, this) <= 0)
2517 Unfreeze(this, false);
2521 MUTATOR_CALLHOOK(PlayerPreThink, this);
2523 if(autocvar_g_vehicles_enter && (time > this.last_vehiclecheck) && !game_stopped && !this.vehicle)
2524 if(IS_PLAYER(this) && !STAT(FROZEN, this) && !IS_DEAD(this) && !IS_INDEPENDENT_PLAYER(this))
2526 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_vehicles_enter_radius, IS_VEHICLE(it) && !IS_DEAD(it) && it.takedamage != DAMAGE_NO,
2530 if(!it.team || SAME_TEAM(this, it))
2531 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER);
2532 else if(autocvar_g_vehicles_steal)
2533 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
2535 else if((it.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(it.owner, this))
2537 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
2541 this.last_vehiclecheck = time + 1;
2544 if(!CS_CVAR(this).cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2546 if(PHYS_INPUT_BUTTON_USE(this) && !CS(this).usekeypressed)
2548 CS(this).usekeypressed = PHYS_INPUT_BUTTON_USE(this);
2551 if (IS_REAL_CLIENT(this))
2552 PrintWelcomeMessage(this);
2554 if (IS_PLAYER(this)) {
2555 if (IS_REAL_CLIENT(this) && time < CS(this).jointime + MIN_SPEC_TIME)
2556 error("Client can't be spawned as player on connection!");
2557 if(!PlayerThink(this))
2560 else if (game_stopped || intermission_running) {
2561 if(intermission_running)
2562 IntermissionThink(this);
2565 else if (IS_REAL_CLIENT(this) && CS(this).autojoin_checked <= 0 && time >= CS(this).jointime + MIN_SPEC_TIME)
2567 bool early_join_requested = (CS(this).autojoin_checked < 0);
2568 CS(this).autojoin_checked = 1;
2569 // don't do this in ClientConnect
2570 // many things can go wrong if a client is spawned as player on connection
2571 if (early_join_requested || MUTATOR_CALLHOOK(AutoJoinOnConnection, this)
2572 || (!(autocvar_sv_spectate || autocvar_g_campaign || (Player_GetForcedTeamIndex(this) == TEAM_FORCE_SPECTATOR))
2573 && (!teamplay || autocvar_g_balance_teams)))
2575 campaign_bots_may_start = true;
2576 if(joinAllowed(this))
2581 else if (IS_OBSERVER(this) || IS_SPEC(this)) {
2582 ObserverOrSpectatorThink(this);
2585 // WEAPONTODO: Add weapon request for this
2586 if (!zoomstate_set) {
2587 bool wep_zoomed = false;
2588 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
2590 .entity weaponentity = weaponentities[slot];
2591 Weapon thiswep = this.(weaponentity).m_weapon;
2592 if(thiswep != WEP_Null && thiswep.wr_zoom)
2593 wep_zoomed += thiswep.wr_zoom(thiswep, this);
2595 SetZoomState(this, PHYS_INPUT_BUTTON_ZOOM(this) || PHYS_INPUT_BUTTON_ZOOMSCRIPT(this) || wep_zoomed);
2598 if (CS(this).teamkill_soundtime && time > CS(this).teamkill_soundtime)
2600 CS(this).teamkill_soundtime = 0;
2602 entity e = CS(this).teamkill_soundsource;
2603 entity oldpusher = e.pusher;
2605 PlayerSound(e, playersound_teamshoot, CH_VOICE, VOL_BASEVOICE, VOICETYPE_LASTATTACKER_ONLY);
2606 e.pusher = oldpusher;
2609 if (CS(this).taunt_soundtime && time > CS(this).taunt_soundtime) {
2610 CS(this).taunt_soundtime = 0;
2611 PlayerSound(this, playersound_taunt, CH_VOICE, VOL_BASEVOICE, VOICETYPE_AUTOTAUNT);
2614 target_voicescript_next(this);
2617 void DrownPlayer(entity this)
2619 if(IS_DEAD(this) || game_stopped || time < game_starttime || this.vehicle
2620 || STAT(FROZEN, this) || this.watertype != CONTENT_WATER)
2622 STAT(AIR_FINISHED, this) = 0;
2626 if (this.waterlevel != WATERLEVEL_SUBMERGED)
2628 if(STAT(AIR_FINISHED, this) && STAT(AIR_FINISHED, this) < time)
2629 PlayerSound(this, playersound_gasp, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
2630 STAT(AIR_FINISHED, this) = 0;
2634 if (!STAT(AIR_FINISHED, this))
2635 STAT(AIR_FINISHED, this) = time + autocvar_g_balance_contents_drowndelay;
2636 if (STAT(AIR_FINISHED, this) < time)
2638 if (this.pain_finished < time)
2640 Damage (this, NULL, NULL, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, DMG_NOWEP, this.origin, '0 0 0');
2641 this.pain_finished = time + 0.5;
2647 .bool move_qcphysics;
2649 void Player_Physics(entity this)
2651 this.movetype = (this.move_qcphysics) ? MOVETYPE_QCPLAYER : this.move_movetype;
2653 if(!this.move_qcphysics)
2656 if(!frametime && !CS(this).pm_frametime)
2659 Movetype_Physics_NoMatchTicrate(this, CS(this).pm_frametime, true);
2661 CS(this).pm_frametime = 0;
2668 Called every frame for each client after the physics are run
2671 void PlayerPostThink (entity this)
2673 Player_Physics(this);
2675 if (autocvar_sv_maxidle > 0 || (IS_PLAYER(this) && autocvar_sv_maxidle_playertospectator > 0))
2676 if (frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2677 if (IS_REAL_CLIENT(this))
2678 if (IS_PLAYER(this) || autocvar_sv_maxidle_alsokickspectators)
2679 if (!intermission_running) // NextLevel() kills all centerprints after setting this true
2681 int totalClients = 0;
2682 if(autocvar_sv_maxidle > 0 && autocvar_sv_maxidle_slots > 0)
2684 // maxidle disabled in local matches by not counting clients (totalClients 0)
2685 if (server_is_dedicated)
2687 FOREACH_CLIENT(IS_REAL_CLIENT(it) || autocvar_sv_maxidle_slots_countbots,
2691 if (maxclients - totalClients > autocvar_sv_maxidle_slots)
2695 else if (IS_PLAYER(this) && autocvar_sv_maxidle_playertospectator > 0)
2697 FOREACH_CLIENT(IS_REAL_CLIENT(it),
2703 if (totalClients < autocvar_sv_maxidle_minplayers)
2705 // idle kick disabled
2706 CS(this).parm_idlesince = time;
2708 else if (time - CS(this).parm_idlesince < 1) // instead of (time == this.parm_idlesince) to support sv_maxidle <= 10
2710 if (CS(this).idlekick_lasttimeleft)
2712 CS(this).idlekick_lasttimeleft = 0;
2713 Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_IDLING);
2718 float maxidle_time = autocvar_sv_maxidle;
2719 if (IS_PLAYER(this) && autocvar_sv_maxidle_playertospectator > 0)
2720 maxidle_time = autocvar_sv_maxidle_playertospectator;
2721 float timeleft = ceil(maxidle_time - (time - CS(this).parm_idlesince));
2722 float countdown_time = max(min(10, maxidle_time - 1), ceil(maxidle_time * 0.33)); // - 1 to support maxidle_time <= 10
2723 if (timeleft == countdown_time && !CS(this).idlekick_lasttimeleft)
2725 if (IS_PLAYER(this) && autocvar_sv_maxidle_playertospectator > 0)
2726 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_MOVETOSPEC_IDLING, timeleft);
2728 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
2730 if (timeleft <= 0) {
2731 if (IS_PLAYER(this) && autocvar_sv_maxidle_playertospectator > 0)
2733 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MOVETOSPEC_IDLING, this.netname, maxidle_time);
2734 PutObserverInServer(this, true);
2738 if (dropclient_schedule(this))
2739 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_KICK_IDLING, this.netname, maxidle_time);
2743 else if (timeleft <= countdown_time) {
2744 if (timeleft != CS(this).idlekick_lasttimeleft)
2745 play2(this, SND(TALK2));
2746 CS(this).idlekick_lasttimeleft = timeleft;
2755 this.solid = SOLID_NOT;
2756 this.takedamage = DAMAGE_NO;
2757 set_movetype(this, MOVETYPE_NONE);
2758 CS(this).teamkill_complain = 0;
2759 CS(this).teamkill_soundtime = 0;
2760 CS(this).teamkill_soundsource = NULL;
2763 if (IS_PLAYER(this)) {
2764 if(this.death_time == time && IS_DEAD(this))
2766 // player's bbox gets resized now, instead of in the damage event that killed the player,
2767 // once all the damage events of this frame have been processed with normal size
2769 setsize(this, this.mins, this.maxs);
2772 UpdateChatBubble(this);
2773 if (CS(this).impulse) ImpulseCommands(this);
2774 GetPressedKeys(this);
2777 CSQCMODEL_AUTOUPDATE(this);
2781 else if (IS_OBSERVER(this) && STAT(PRESSED_KEYS, this))
2783 CS(this).pressedkeys = 0;
2784 STAT(PRESSED_KEYS, this) = 0;
2787 if (this.waypointsprite_attachedforcarrier) {
2788 float hp = healtharmor_maxdamage(GetResource(this, RES_HEALTH), GetResource(this, RES_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x;
2789 WaypointSprite_UpdateHealth(this.waypointsprite_attachedforcarrier, hp);
2792 CSQCMODEL_AUTOUPDATE(this);
2795 // hack to copy the button fields from the client entity to the Client State
2796 void PM_UpdateButtons(entity this, entity store)
2799 store.impulse = this.impulse;
2802 bool typing = this.buttonchat || this.button12;
2804 store.button0 = (typing) ? 0 : this.button0;
2806 store.button2 = (typing) ? 0 : this.button2;
2807 store.button3 = (typing) ? 0 : this.button3;
2808 store.button4 = this.button4;
2809 store.button5 = (typing) ? 0 : this.button5;
2810 store.button6 = this.button6;
2811 store.button7 = this.button7;
2812 store.button8 = this.button8;
2813 store.button9 = this.button9;
2814 store.button10 = this.button10;
2815 store.button11 = this.button11;
2816 store.button12 = this.button12;
2817 store.button13 = this.button13;
2818 store.button14 = this.button14;
2819 store.button15 = this.button15;
2820 store.button16 = this.button16;
2821 store.buttonuse = this.buttonuse;
2822 store.buttonchat = this.buttonchat;
2824 store.cursor_active = this.cursor_active;
2825 store.cursor_screen = this.cursor_screen;
2826 store.cursor_trace_start = this.cursor_trace_start;
2827 store.cursor_trace_endpos = this.cursor_trace_endpos;
2828 store.cursor_trace_ent = this.cursor_trace_ent;
2830 store.ping = this.ping;
2831 store.ping_packetloss = this.ping_packetloss;
2832 store.ping_movementloss = this.ping_movementloss;
2834 store.v_angle = this.v_angle;
2835 store.movement = this.movement;
2838 NET_HANDLE(fpsreport, bool)
2840 int fps = ReadShort();
2841 PlayerScore_Set(sender, SP_FPS, fps);