]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/cl_client.qc
ip ban code: minor bugfixes
[divverent/nexuiz.git] / data / qcsrc / server / cl_client.qc
1 void info_player_start (void)
2 {
3         info_player_deathmatch();
4 }
5
6 void info_player_deathmatch (void)
7 {
8         self.classname = "info_player_deathmatch";
9         relocate_spawnpoint();
10 }
11
12 float spawn_allbad;
13 float spawn_allgood;
14 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
15 {
16         local entity spot, player, nextspot, previousspot, newfirstspot;
17         local float pcount;
18         spot = firstspot;
19         newfirstspot = world;
20         previousspot = world;
21         spawn_allgood = TRUE;
22         spawn_allbad = TRUE;
23         while (spot)
24         {
25                 nextspot = spot.chain;
26                 // count team mismatches as bad spots
27
28                 local float spotactive;
29                 spotactive = 1;
30
31                 // filter out spots for assault
32                 if(spot.target != "") {
33                         local entity ent;
34                         ent = find(world, targetname, spot.target);
35                         while(ent) {
36                                 if(ent.classname == "target_objective")
37                                         if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
38                                                 spotactive = 0;
39                                 ent = find(ent, targetname, spot.target);
40                         }
41                 }
42
43                 if (spot.team == teamcheck && spotactive > 0)
44                 {
45                         pcount = 0;
46                         player = playerlist;
47                         while (player)
48                         {
49                                 if (player != self)
50                                 if (vlen(player.origin - spot.origin) < mindist)
51                                         pcount = pcount + 1;
52                                 player = player.chain;
53                         }
54                         if (!pcount)
55                         {
56                                 spawn_allbad = FALSE;
57                                 if (newfirstspot)
58                                         previousspot.chain = spot;
59                                 else
60                                         newfirstspot = spot;
61                                 previousspot = spot;
62                                 spot.chain = world;
63                         }
64                         else
65                                 spawn_allgood = FALSE;
66                 }
67                 spot = nextspot;
68         }
69         // if we couldn't find ANY good points, return the original list
70         if (!newfirstspot)
71                 newfirstspot = firstspot;
72         return newfirstspot;
73 }
74
75 entity Spawn_RandomPoint(entity firstspot)
76 {
77         local entity spot;
78         local float numspots;
79         // count number of spots
80         numspots = 0;
81         spot = firstspot;
82         while (spot)
83         {
84                 numspots = numspots + 1;
85                 spot = spot.chain;
86         }
87         // pick a random one
88         numspots = numspots * random();
89         spot = firstspot;
90         while (spot.chain && numspots >= 1)
91         {
92                 numspots = numspots - 1;
93                 spot = spot.chain;
94         }
95         return spot;
96 }
97
98 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
99 {
100         local entity best, spot, player;
101         local float bestrating, rating;
102         best = world;
103         bestrating = -1000000;
104         spot = firstspot;
105         while (spot)
106         {
107                 rating = 1000000000;
108                 player = playerlist;
109                 while (player)
110                 {
111                         if (player != self)
112                                 rating = min(rating, vlen(player.origin - spot.origin));
113                         player = player.chain;
114                 }
115                 rating = rating + random() * 16;
116                 if (bestrating < rating)
117                 {
118                         best = spot;
119                         bestrating = rating;
120                 }
121                 spot = spot.chain;
122         }
123         return best;
124 }
125
126 /*
127 =============
128 SelectSpawnPoint
129
130 Finds a point to respawn
131 =============
132 */
133 entity SelectSpawnPoint (float anypoint)
134 {
135         local float teamcheck;
136         local entity spot, firstspot, playerlist;
137
138         spot = find (world, classname, "testplayerstart");
139         if (spot)
140                 return spot;
141
142         teamcheck = 0;
143
144         if((!anypoint && cvar("g_ctf")) || cvar("g_assault") )
145                 teamcheck = self.team;
146
147         // get the list of players
148         playerlist = findchain(classname, "player");
149         // get the entire list of spots
150         firstspot = findchain(classname, "info_player_deathmatch");
151         // filter out the bad ones
152         // (note this returns the original list if none survived)
153         firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
154
155         // there is 50/50 chance of choosing a random spot or the furthest spot
156         // (this means that roughly every other spawn will be furthest, so you
157         // usually won't get fragged at spawn twice in a row)
158         if (arena_roundbased)
159         {
160                 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
161                 spot = Spawn_RandomPoint(firstspot);
162         }
163         else if (random() > 0.5 || spawn_allbad || spawn_allgood)
164                 spot = Spawn_RandomPoint(firstspot);
165         else
166                 spot = Spawn_FurthestPoint(firstspot, playerlist);
167
168         if (!spot)
169         {
170                 if(cvar("spawn_debug"))
171                         GotoNextMap();
172                 else
173                         error ("PutClientInServer: no start points on level");
174         }
175
176         return spot;
177 }
178
179 /*
180 =============
181 CheckPlayerModel
182
183 Checks if the argument string can be a valid playermodel.
184 Returns a valid one in doubt.
185 =============
186 */
187 string FallbackPlayerModel = "models/player/marine.zym";
188 string CheckPlayerModel(string plyermodel) {
189         if(strlen(plyermodel) < 4)
190                 return FallbackPlayerModel;
191         if( substring(plyermodel,0,14) != "models/player/")
192                 return FallbackPlayerModel;
193         else if(cvar("sv_servermodelsonly"))
194         {
195                 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
196                         return FallbackPlayerModel;
197                 if(!fexists(plyermodel))
198                         return FallbackPlayerModel;
199         }
200         return plyermodel;
201 }
202
203 /*
204 =============
205 Client_customizeentityforclient
206
207 LOD reduction
208 =============
209 */
210 float Client_customizeentityforclient()
211 {
212 #ifdef ALLOW_VARIABLE_LOD
213         // self: me
214         // other: the player viewing me
215         float distance;
216         float f;
217
218         if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
219                 return TRUE;
220
221         if(other.cvar_cl_playerdetailreduction <= 0)
222         {
223                 if(other.cvar_cl_playerdetailreduction <= -2)
224                         self.modelindex = self.modelindex_lod2;
225                 else if(other.cvar_cl_playerdetailreduction <= -1)
226                         self.modelindex = self.modelindex_lod1;
227                 else
228                         self.modelindex = self.modelindex_lod0;
229         }
230         else
231         {
232                 distance = vlen(self.origin - other.origin);
233                 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
234                 if(f > 10000)
235                         self.modelindex = self.modelindex_lod2;
236                 else if(f > 5000)
237                         self.modelindex = self.modelindex_lod1;
238                 else
239                         self.modelindex = self.modelindex_lod0;
240         }
241 #endif
242
243         return TRUE;
244 }
245
246 void setmodel_lod(entity e, string modelname)
247 {
248 #ifdef ALLOW_VARIABLE_LOD
249         string s;
250
251         s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1.zym");
252         if(fexists(s))
253         {
254                 precache_model(s);
255                 setmodel(e, s); // players have high precision
256                 self.modelindex_lod1 = self.modelindex;
257         }
258         else
259                 self.modelindex_lod1 = -1;
260
261         s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2.zym");
262         if(fexists(s))
263         {
264                 precache_model(s);
265                 setmodel(e, s); // players have high precision
266                 self.modelindex_lod2 = self.modelindex;
267         }
268         else
269                 self.modelindex_lod2 = -1;
270
271         precache_model(modelname);
272         setmodel(e, modelname); // players have high precision
273         self.modelindex_lod0 = self.modelindex;
274
275         if(self.modelindex_lod1 < 0)
276                 self.modelindex_lod1 = self.modelindex;
277
278         if(self.modelindex_lod2 < 0)
279                 self.modelindex_lod2 = self.modelindex;
280 #else
281         precache_model(modelname);
282         setmodel(e, modelname); // players have high precision
283 #endif
284 }
285
286 /*
287 =============
288 PutObserverInServer
289
290 putting a client as observer in the server
291 =============
292 */
293 void PutObserverInServer (void)
294 {
295         entity  spot;
296         spot = SelectSpawnPoint (FALSE);
297         RemoveGrapplingHook(self); // Wazat's Grappling Hook
298
299         if(clienttype(self) == CLIENTTYPE_REAL)
300         {
301                 msg_entity = self;
302                 WriteByte(MSG_ONE, SVC_SETVIEW);
303                 WriteEntity(MSG_ONE, self);
304         }
305
306         DropAllRunes(self);
307         kh_Key_DropAll(self, TRUE);
308
309         if(self.flagcarried)
310                 DropFlag(self.flagcarried);
311
312         WaypointSprite_PlayerDead();
313
314         DistributeFragsAmongTeam(self, self.team, 1);
315
316         if(self.frags <= 0 && self.frags > -666 && cvar("g_lms") && self.killcount != -666)
317                 bprint ("^4", self.netname, "^4 has no more lives left\n");
318         else if(self.killcount != -666)
319                 bprint ("^4", self.netname, "^4 is spectating now\n");
320
321         self.classname = "observer";
322         self.health = -666;
323         self.takedamage = DAMAGE_NO;
324         self.solid = SOLID_NOT;
325         self.movetype = MOVETYPE_NOCLIP;
326         self.flags = FL_CLIENT | FL_NOTARGET;
327         self.armorvalue = 666;
328         self.effects = 0;
329         self.armorvalue = cvar("g_balance_armor_start");
330         self.pauserotarmor_finished = 0;
331         self.pauserothealth_finished = 0;
332         self.pauseregen_finished = 0;
333         self.damageforcescale = 0;
334         self.death_time = 0;
335         self.dead_time = 0;
336         self.dead_frame = 0;
337         self.die_frame = 0;
338         self.deaths = 0;
339         self.alpha = 0;
340         self.scale = 0;
341         self.fade_time = 0;
342         self.pain_frame = 0;
343         self.pain_finished = 0;
344         self.strength_finished = 0;
345         self.invincible_finished = 0;
346         self.pushltime = 0;
347         self.think = SUB_Null;
348         self.nextthink = 0;
349         self.hook_time = 0;
350         self.runes = 0;
351         self.deadflag = DEAD_NO;
352         self.angles = spot.angles;
353         self.angles_z = 0;
354         self.fixangle = TRUE;
355         self.crouch = FALSE;
356
357         self.view_ofs = PL_VIEW_OFS;
358         setorigin (self, spot.origin);
359         setsize (self, '0 0 0', '0 0 0');
360         self.oldorigin = self.origin;
361         self.items = 0;
362         self.model = "";
363         self.modelindex = 0;
364         self.weapon = 0;
365         self.weaponmodel = "";
366         self.weaponentity = world;
367         self.killcount = -666;
368         self.velocity = '0 0 0';
369         self.avelocity = '0 0 0';
370         self.punchangle = '0 0 0';
371         self.punchvector = '0 0 0';
372         self.oldvelocity = self.velocity;
373         self.customizeentityforclient = Client_customizeentityforclient;
374
375         if(cvar("g_arena"))
376         {
377                 if(self.frags != -2)
378                 {
379                         Spawnqueue_Insert(self);
380                 }
381                 else
382                 {
383                         Spawnqueue_Unmark(self);
384                         Spawnqueue_Remove(self);
385                 }
386         }
387         else if(!cvar("g_lms"))
388                 self.frags = -666;
389 }
390
391
392 /*
393 =============
394 PutClientInServer
395
396 Called when a client spawns in the server
397 =============
398 */
399 void PutClientInServer (void)
400 {
401         if(clienttype(self) == CLIENTTYPE_BOT)
402         {
403                 self.classname = "player";
404         }
405         else if(clienttype(self) == CLIENTTYPE_REAL)
406         {
407                 msg_entity = self;
408                 WriteByte(MSG_ONE, SVC_SETVIEW);
409                 WriteEntity(MSG_ONE, self);
410         }
411
412         // player is dead and becomes observer
413         if(cvar("g_lms") && self.frags < 1)
414                 self.classname = "observer";
415
416         if(cvar("g_arena"))
417         if(!self.spawned)
418                 self.classname = "observer";
419
420         if(self.classname == "player") {
421                 entity  spot;
422
423                 spot = SelectSpawnPoint (FALSE);
424
425                 RemoveGrapplingHook(self); // Wazat's Grappling Hook
426
427                 self.classname = "player";
428                 self.iscreature = TRUE;
429                 self.movetype = MOVETYPE_WALK;
430                 self.solid = SOLID_SLIDEBOX;
431                 self.flags = FL_CLIENT;
432                 self.takedamage = DAMAGE_AIM;
433                 self.effects = 0;
434                 self.air_finished = time + 12;
435                 self.dmg = 2;
436
437                 self.ammo_shells = start_ammo_shells;
438                 self.ammo_nails = start_ammo_nails;
439                 self.ammo_rockets = start_ammo_rockets;
440                 self.ammo_cells = start_ammo_cells;
441                 self.health = start_health;
442                 self.armorvalue = start_armorvalue;
443                 self.items = start_items;
444                 self.switchweapon = start_switchweapon;
445                 self.weapon = 0;
446                 self.jump_interval = time;
447
448                 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
449                 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
450                 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
451                 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
452                 self.damageforcescale = 2;
453                 self.death_time = 0;
454                 self.dead_time = 0;
455                 self.dead_frame = 0;
456                 self.die_frame = 0;
457                 self.alpha = 0;
458                 self.scale = 0;
459                 self.fade_time = 0;
460                 self.pain_frame = 0;
461                 self.pain_finished = 0;
462                 self.strength_finished = 0;
463                 self.invincible_finished = 0;
464                 self.pushltime = 0;
465                 //self.speed_finished = 0;
466                 //self.slowmo_finished = 0;
467                 // players have no think function
468                 self.think = SUB_Null;
469                 self.nextthink = 0;
470                 self.hook_time = 0;
471
472                 self.runes = 0;
473
474                 self.deadflag = DEAD_NO;
475
476                 self.angles = spot.angles;
477
478                 self.angles_z = 0; // never spawn tilted even if the spot says to
479                 self.fixangle = TRUE; // turn this way immediately
480                 self.velocity = '0 0 0';
481                 self.avelocity = '0 0 0';
482                 self.punchangle = '0 0 0';
483                 self.punchvector = '0 0 0';
484                 self.oldvelocity = self.velocity;
485
486                 self.viewzoom = 0.6;
487                 self.has_zoomed = 0;
488
489                 self.customizeentityforclient = Client_customizeentityforclient;
490
491                 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
492                         local string defaultmodel;
493                         defaultmodel = cvar_string("sv_defaultplayermodel");
494                         setmodel_lod (self, defaultmodel);
495                         self.skin = stof(cvar_string("sv_defaultplayerskin"));
496                 } else {
497                         self.playermodel = CheckPlayerModel(self.playermodel);
498                         setmodel_lod (self, self.playermodel);
499                         if(teams_matter)
500                                 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
501                         else
502                                 self.skin = stof(self.playerskin);
503                 }
504
505                 self.crouch = FALSE;
506                 self.view_ofs = PL_VIEW_OFS;
507                 setsize (self, PL_MIN, PL_MAX);
508                 self.spawnorigin = spot.origin;
509                 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
510                 // don't reset back to last position, even if new position is stuck in solid
511                 self.oldorigin = self.origin;
512
513                 if(cvar("g_arena"))
514                 {
515                         Spawnqueue_Remove(self);
516                         Spawnqueue_Mark(self);
517                 }
518
519                 self.event_damage = PlayerDamage;
520
521                 self.bot_attack = TRUE;
522
523                 self.statdraintime = time + 5;
524                 self.button0 = self.button1 = self.button2 = self.button3 = 0;
525
526                 if(self.killcount == -666) {
527                         self.killcount = 0;
528                         if(!cvar("g_arena"))
529                         if(!cvar("g_lms"))
530                                 self.frags = 0;
531                 }
532
533                 self.cnt = WEP_LASER;
534                 self.nixnex_lastchange_id = -1;
535
536                 CL_SpawnWeaponentity();
537                 self.alpha = default_player_alpha;
538                 self.exteriorweaponentity.alpha = default_weapon_alpha;
539
540                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
541                 self.lms_traveled_distance = 0;
542
543                 if(cvar("spawn_debug"))
544                 {
545                         sprint(self, strcat("spawnpoint origin:  ", vtos(spot.origin), "\n"));
546                         remove(spot);   // usefull for checking if there are spawnpoints, that let drop through the floor
547                 }
548
549                 //stuffcmd(self, "chase_active 0");
550                 //stuffcmd(self, "set viewsize $tmpviewsize \n");
551
552                 if (cvar("g_spawnsound"))
553                         sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
554
555                 if(cvar("g_assault")) {
556                         if(self.team == assault_attacker_team)
557                                 centerprint(self, "You are attacking!\n");
558                         else
559                                 centerprint(self, "You are defending!\n");
560                 }
561
562         } else if(self.classname == "observer") {
563                 PutObserverInServer ();
564         }
565 }
566
567 /*
568 =============
569 SetNewParms
570 =============
571 */
572 void SetNewParms (void)
573 {
574
575 }
576
577 /*
578 =============
579 SetChangeParms
580 =============
581 */
582 void SetChangeParms (void)
583 {
584
585 }
586
587 /*
588 =============
589 ClientKill
590
591 Called when a client types 'kill' in the console
592 =============
593 */
594 void ClientKill (void)
595 {
596         Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
597 }
598
599 void FixClientCvars(entity e)
600 {
601         // send prediction settings to the client
602         stuffcmd(e, "\nin_bindmap 0 0\n");
603         stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
604         stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
605         stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
606         stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
607         stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
608         stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
609         stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
610         stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
611         stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
612         stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
613         stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
614         stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
615         stuffcmd(e, "cl_movement_edgefriction 1\n");
616 }
617
618 /*
619 =============
620 ClientConnect
621
622 Called when a client connects to the server
623 =============
624 */
625 string ColoredTeamName(float t);
626 //void dom_player_join_team(entity pl);
627 void ClientConnect (void)
628 {
629         local string s;
630
631         if(Ban_IsClientBanned(self))
632         {
633                 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
634                 dropclient(self);
635                 bprint(s);
636                 return;
637         }
638
639         self.classname = "player_joining";
640         self.flags = self.flags | FL_CLIENT;
641         self.version_nagtime = time + 10 + random() * 10;
642
643         if(player_count<0)
644         {
645                 dprint("BUG player count is lower than zero, this cannot happen!\n");
646                 player_count = 0;
647         }
648
649         bot_clientconnect();
650
651         //if(cvar("g_domination"))
652         //      dom_player_join_team(self);
653
654         //JoinBestTeam(self, FALSE);
655
656         if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
657                 self.classname = "observer";
658         } else {
659                 self.classname = "player";
660                 campaign_bots_may_start = 1;
661         }
662
663         self.playerid = (playerid_last = playerid_last + 1);
664         if(cvar("sv_eventlog"))
665         {
666                 if(clienttype(self) == CLIENTTYPE_REAL)
667                         s = "player";
668                 else
669                         s = "bot";
670                 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
671                 s = strcat(":team:", ftos(self.playerid), ":");
672                 s = strcat(s, ftos(self.team));
673                 GameLogEcho(s, FALSE);
674         }
675
676         //stuffcmd(self, "set tmpviewsize $viewsize \n");
677
678         bprint ("^4",self.netname);
679         bprint ("^4 connected");
680
681         if(cvar("g_domination") || cvar("g_ctf"))
682         {
683                 bprint(" and joined the ");
684                 bprint(ColoredTeamName(self.team));
685         }
686
687         bprint("\n");
688
689         self.welcomemessage_time = 0;
690
691         stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
692         // TODO: is this being used for anything else than cd tracks?
693         // Remember: SVC_CDTRACK exists. Maybe it should be used.
694
695         FixClientCvars(self);
696
697         // waypoint sprites
698         WaypointSprite_InitClient(self);
699
700         // Wazat's grappling hook
701         SetGrappleHookBindings();
702
703         // get autoswitch state from player when he toggles it
704         stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
705
706         // get version info from player
707         stuffcmd(self, "cmd clientversion $gameversion\n");
708
709         // get other cvars from player
710         GetCvars(0);
711
712         // set cvar for team scoreboard
713         if (teams_matter)
714         {
715                 local float t;
716                 t = cvar("teamplay");
717                 // we have to stuff the correct teamplay value because if this is a listen server, this changes the teamplay mode of the server itself, which is bad
718                 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
719         }
720         else
721                 stuffcmd(self, "set teamplay 0\n");
722
723         if(cvar("g_lms"))
724         {
725                 self.frags = cvar("fraglimit");
726                 // no fraglimit was set, so player gets 999 lives
727                 if(self.frags < 1)
728                         self.frags = 999;
729
730                 self.frags = LMS_NewPlayerLives();
731                 if(!self.frags)
732                 {
733                         self.frags = -666;
734                 }
735         }
736         else if(cvar("g_arena"))
737         {
738                 self.classname = "observer";
739                 Spawnqueue_Insert(self);
740         }
741
742         bot_relinkplayerlist();
743
744         self.jointime = time;
745 }
746
747 /*
748 =============
749 ClientDisconnect
750
751 Called when a client disconnects from the server
752 =============
753 */
754 void(entity e) DropFlag;
755 .entity chatbubbleentity;
756 .entity teambubbleentity;
757 void ClientDisconnect (void)
758 {
759         float save;
760         if(cvar("sv_eventlog"))
761                 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
762         bprint ("^4",self.netname);
763         bprint ("^4 disconnected\n");
764
765         if (self.chatbubbleentity)
766         {
767                 remove (self.chatbubbleentity);
768                 self.chatbubbleentity = world;
769         }
770
771         if (self.teambubbleentity)
772         {
773                 remove (self.teambubbleentity);
774                 self.teambubbleentity = world;
775         }
776
777         WaypointSprite_PlayerGone();
778
779         DropAllRunes(self);
780         kh_Key_DropAll(self, TRUE);
781
782         if(self.flagcarried)
783                 DropFlag(self.flagcarried);
784
785         DistributeFragsAmongTeam(self, self.team, 1);
786
787         save = self.flags;
788         self.flags = self.flags - (self.flags & FL_CLIENT);
789         bot_relinkplayerlist();
790         self.flags = save;
791
792         // remove laserdot
793         if(self.weaponentity)
794                 if(self.weaponentity.lasertarget)
795                         remove(self.weaponentity.lasertarget);
796
797         if(cvar("g_arena"))
798         {
799                 Spawnqueue_Unmark(self);
800                 Spawnqueue_Remove(self);
801         }
802
803         // free cvars
804         GetCvars(-1);
805 }
806
807 .float buttonchat;
808 void() ChatBubbleThink =
809 {
810         self.nextthink = time;
811         if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
812         {
813                 self.owner.chatbubbleentity = world;
814                 remove(self);
815                 return;
816         }
817         setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
818         if (self.owner.buttonchat && !self.owner.deadflag)
819                 self.model = self.mdl;
820         else
821                 self.model = "";
822 };
823
824 void() UpdateChatBubble =
825 {
826         if (!self.modelindex)
827                 return;
828         // spawn a chatbubble entity if needed
829         if (!self.chatbubbleentity)
830         {
831                 self.chatbubbleentity = spawn();
832                 self.chatbubbleentity.owner = self;
833                 self.chatbubbleentity.exteriormodeltoclient = self;
834                 self.chatbubbleentity.think = ChatBubbleThink;
835                 self.chatbubbleentity.nextthink = time;
836                 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
837                 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
838                 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
839                 self.chatbubbleentity.model = "";
840                 self.chatbubbleentity.effects = EF_LOWPRECISION;
841         }
842 }
843
844
845 void() TeamBubbleThink =
846 {
847         self.nextthink = time;
848         if (!self.owner.modelindex || self.owner.teambubbleentity != self)
849         {
850                 self.owner.teambubbleentity = world;
851                 remove(self);
852                 return;
853         }
854 //      setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');  // bandwidth hog. setattachment does this now
855         if (self.owner.buttonchat || self.owner.deadflag)
856                 self.model = "";
857         else
858                 self.model = self.mdl;
859
860 };
861
862 float() TeamBubble_customizeentityforclient
863 {
864         return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
865 }
866
867 void() UpdateTeamBubble =
868 {
869         if (!self.modelindex || !cvar("teamplay"))
870                 return;
871         // spawn a teambubble entity if needed
872         if (!self.teambubbleentity && cvar("teamplay"))
873         {
874                 self.teambubbleentity = spawn();
875                 self.teambubbleentity.owner = self;
876                 self.teambubbleentity.exteriormodeltoclient = self;
877                 self.teambubbleentity.think = TeamBubbleThink;
878                 self.teambubbleentity.nextthink = time;
879                 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
880 //              setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
881                 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
882                 setattachment(self.teambubbleentity, self, "");  // sticks to moving player better, also conserves bandwidth
883                 self.teambubbleentity.mdl = self.teambubbleentity.model;
884                 self.teambubbleentity.model = self.teambubbleentity.mdl;
885                 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
886                 self.teambubbleentity.effects = EF_LOWPRECISION;
887         }
888 }
889
890 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
891 // added to the model skins
892 /*void() UpdateColorModHack =
893 {
894         local float c;
895         c = self.clientcolors & 15;
896         // LordHavoc: only bothering to support white, green, red, yellow, blue
897              if (teamplay == 0) self.colormod = '0 0 0';
898         else if (c ==  0) self.colormod = '1.00 1.00 1.00';
899         else if (c ==  3) self.colormod = '0.10 1.73 0.10';
900         else if (c ==  4) self.colormod = '1.73 0.10 0.10';
901         else if (c == 12) self.colormod = '1.22 1.22 0.10';
902         else if (c == 13) self.colormod = '0.10 0.10 1.73';
903         else self.colormod = '1 1 1';
904 };*/
905
906 void respawn(void)
907 {
908         CopyBody(1);
909         PutClientInServer();
910 }
911
912 void player_powerups (void)
913 {
914         if (cvar("g_minstagib"))
915         {
916                 self.effects = EF_FULLBRIGHT;
917                 if (self.items & IT_STRENGTH)
918                 {
919                         if (time > self.strength_finished)
920                         {
921                                 self.alpha = default_player_alpha;
922                                 self.exteriorweaponentity.alpha = default_weapon_alpha;
923                                 self.items = self.items - (self.items & IT_STRENGTH);
924                                 sprint(self, "^3Invisibility has worn off\n");
925                         }
926                 }
927                 else
928                 {
929                         if (time < self.strength_finished)
930                         {
931                                 self.alpha = cvar("g_minstagib_invis_alpha");
932                                 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
933                                 self.items = self.items | IT_STRENGTH;
934                                 sprint(self, "^3You are invisible\n");
935                         }
936                 }
937
938                 if (self.items & IT_INVINCIBLE)
939                 {
940                         if (time > self.invincible_finished)
941                         {
942                                 self.items = self.items - (self.items & IT_INVINCIBLE);
943                                 sprint(self, "^3Speed has worn off\n");
944                         }
945                 }
946                 else
947                 {
948                         if (time < self.invincible_finished)
949                         {
950                                 self.items = self.items | IT_INVINCIBLE;
951                                 sprint(self, "^3You are on speed\n");
952                         }
953                 }
954                 return;
955         }
956
957         self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
958         if (self.items & IT_STRENGTH)
959         {
960                 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
961                 if (time > self.strength_finished)
962                 {
963                         self.items = self.items - (self.items & IT_STRENGTH);
964                         sprint(self, "^3Strength has worn off\n");
965                 }
966         }
967         else
968         {
969                 if (time < self.strength_finished)
970                 {
971                         self.items = self.items | IT_STRENGTH;
972                         sprint(self, "^3Strength infuses your weapons with devastating power\n");
973                 }
974         }
975         if (self.items & IT_INVINCIBLE)
976         {
977                 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
978                 if (time > self.invincible_finished)
979                 {
980                         self.items = self.items - (self.items & IT_INVINCIBLE);
981                         sprint(self, "^3Shield has worn off\n");
982                 }
983         }
984         else
985         {
986                 if (time < self.invincible_finished)
987                 {
988                         self.items = self.items | IT_INVINCIBLE;
989                         sprint(self, "^3Shield surrounds you\n");
990                 }
991         }
992
993         if (cvar("g_fullbrightplayers"))
994                 self.effects = self.effects | EF_FULLBRIGHT;
995
996         // midair gamemode: damage only while in the air
997         // if in midair mode, being on ground grants temporary invulnerability
998         // (this is so that multishot weapon don't clear the ground flag on the
999         // first damage in the frame, leaving the player vulnerable to the
1000         // remaining hits in the same frame)
1001         if (self.flags & FL_ONGROUND)
1002         if (cvar("g_midair"))
1003                 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1004
1005         if (time < self.spawnshieldtime)
1006                 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1007 }
1008
1009 float CalcRegen(float current, float stable, float regenfactor)
1010 {
1011         if(current > stable)
1012                 return current;
1013         else if(current > stable - 0.25) // when close enough, "snap"
1014                 return stable;
1015         else
1016                 return min(stable, current + (stable - current) * regenfactor * frametime);
1017 }
1018
1019 void player_regen (void)
1020 {
1021         float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1022         maxh = cvar("g_balance_health_stable");
1023         maxa = cvar("g_balance_armor_stable");
1024         limith = cvar("g_balance_health_limit");
1025         limita = cvar("g_balance_armor_limit");
1026
1027         if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
1028                 return;
1029
1030         max_mod = regen_mod = rot_mod = limit_mod = 1;
1031
1032         if (self.runes & RUNE_REGEN)
1033         {
1034                 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1035                 {
1036                         regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1037                         max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1038                         limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1039                 }
1040                 else
1041                 {
1042                         regen_mod = cvar("g_balance_rune_regen_regenrate");
1043                         max_mod = cvar("g_balance_rune_regen_hpmod");
1044                         limit_mod = cvar("g_balance_rune_regen_limitmod");
1045                 }
1046         }
1047         else if (self.runes & CURSE_VENOM)
1048         {
1049                 max_mod = cvar("g_balance_curse_venom_hpmod");
1050                 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1051                         rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1052                 else
1053                         rot_mod = cvar("g_balance_curse_venom_rotrate");
1054                 limit_mod = cvar("g_balance_curse_venom_limitmod");
1055                 //if (!self.runes & RUNE_REGEN)
1056                 //      rot_mod = cvar("g_balance_curse_venom_rotrate");
1057         }
1058         maxh = maxh * max_mod;
1059         //maxa = maxa * max_mod;
1060         limith = limith * limit_mod;
1061         limita = limita * limit_mod;
1062
1063         if (self.armorvalue > maxa)
1064         {
1065                 if (time > self.pauserotarmor_finished)
1066                 {
1067                         self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1068                         self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1069                 }
1070         }
1071         else if (self.armorvalue < maxa)
1072         {
1073                 if (time > self.pauseregen_finished)
1074                 {
1075                         self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1076                         self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1077                 }
1078         }
1079         if (self.health > maxh)
1080         {
1081                 if (time > self.pauserothealth_finished)
1082                 {
1083                         self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1084                         self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1085                 }
1086         }
1087         else if (self.health < maxh)
1088         {
1089                 if (time > self.pauseregen_finished)
1090                 {
1091                         self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1092                         self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1093                 }
1094         }
1095
1096         if (self.health > limith)
1097                 self.health = limith;
1098         if (self.armorvalue > limita)
1099                 self.armorvalue = limita;
1100
1101         // if player rotted to death...  die!
1102         if(self.health < 1)
1103                 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1104 }
1105
1106 /*
1107 ======================
1108 spectate mode routines
1109 ======================
1110 */
1111 void SpectateCopy(entity spectatee) {
1112         self.armortype = spectatee.armortype;
1113         self.armorvalue = spectatee.armorvalue;
1114         self.currentammo = spectatee.currentammo;
1115         self.effects = spectatee.effects;
1116         self.health = spectatee.health;
1117         self.impulse = 0;
1118         self.items = spectatee.items;
1119         self.punchangle = spectatee.punchangle;
1120         self.view_ofs = spectatee.view_ofs;
1121         self.v_angle = spectatee.v_angle;
1122         self.viewzoom = spectatee.viewzoom;
1123         setorigin(self, spectatee.origin);
1124         setsize(self, spectatee.mins, spectatee.maxs);
1125 }
1126
1127 void SpectateUpdate() {
1128         if(!self.enemy)
1129                         PutObserverInServer();
1130
1131         if (self != self.enemy) {
1132                 if(self.enemy.flags & FL_NOTARGET)
1133                         PutObserverInServer();
1134                 SpectateCopy(self.enemy);
1135                 self.dmg_take = self.enemy.dmg_take;
1136                 self.dmg_save = self.enemy.dmg_save;
1137                 self.dmg_inflictor = self.enemy.dmg_inflictor;
1138                 self.fixangle = TRUE;
1139                 self.angles = self.enemy.v_angle;
1140                 //msg_entity = self;
1141                 //WriteByte(MSG_ONE, SVC_SETANGLE);
1142                 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1143                 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1144                 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1145         }
1146 }
1147
1148 float SpectateNext() {
1149         other = find(self.enemy, classname, "player");
1150         if (!other) {
1151                 other = find(other, classname, "player");
1152         }
1153         if (other) {
1154                 self.enemy = other;
1155         }
1156         if(self.enemy.classname == "player") {
1157                 msg_entity = self;
1158                 WriteByte(MSG_ONE, SVC_SETVIEW);
1159                 WriteEntity(MSG_ONE, self.enemy);
1160                 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1161                 SpectateUpdate();
1162                 return 1;
1163         } else {
1164                 return 0;
1165         }
1166 }
1167
1168 /*
1169 =============
1170 ShowRespawnCountdown()
1171
1172 Update a respawn countdown display.
1173 =============
1174 */
1175 void ShowRespawnCountdown()
1176 {
1177         float number;
1178         if(self.deadflag == DEAD_NO) // just respawned?
1179                 return;
1180         else
1181         {
1182                 number = ceil(self.death_time - time);
1183                 if(number <= 0)
1184                         return;
1185                 if(number <= self.respawn_countdown)
1186                 {
1187                         self.respawn_countdown = number - 1;
1188                         if(ceil(self.death_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
1189                                 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1190                 }
1191         }
1192 }
1193
1194 void LeaveSpectatorMode()
1195 {
1196         if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1197                 self.classname = "player";
1198                 if(cvar("g_campaign") || cvar("g_balance_teams"))
1199                         JoinBestTeam(self, 0);
1200                 if(cvar("g_campaign"))
1201                         campaign_bots_may_start = 1;
1202                 PutClientInServer();
1203                 if(!(self.flags & FL_NOTARGET))
1204                         bprint ("^4", self.netname, "^4 is playing now\n");
1205                 centerprint(self,"");
1206                 return;
1207         } else {
1208                 stuffcmd(self,"menu_showteamselect\n");
1209                 return;
1210         }
1211 }
1212
1213 /*
1214 =============
1215 PlayerPreThink
1216
1217 Called every frame for each client before the physics are run
1218 =============
1219 */
1220 void() ctf_setstatus;
1221 .float vote_nagtime;
1222 void PlayerPreThink (void)
1223 {
1224         // version nagging
1225         if(self.version_nagtime)
1226                 if(self.cvar_g_nexuizversion)
1227                         if(time > self.version_nagtime)
1228                         {
1229                                 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1230                                         if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1231                                         {
1232                                                 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n");
1233                                                 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1234                                         }
1235                                 self.version_nagtime = 0;
1236                         }
1237
1238         // vote nagging
1239         if(self.cvar_scr_centertime)
1240                 if(time > self.vote_nagtime)
1241                 {
1242                         VoteNag();
1243                         self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1244                 }
1245
1246         // GOD MODE info
1247         if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1248         {
1249                 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1250                 self.max_armorvalue = 0;
1251         }
1252
1253         if(self.classname == "player") {
1254                 local vector m1, m2;
1255
1256 //              if(self.netname == "Wazat")
1257 //                      bprint(self.classname, "\n");
1258
1259                 CheckRules_Player();
1260
1261                 if(self.button7)
1262                         PrintWelcomeMessage(self);
1263
1264                 if(cvar("g_lms") || !cvar("sv_spectate"))
1265                 if((time - self.jointime) <= cvar("welcome_message_time"))
1266                         PrintWelcomeMessage(self);
1267
1268                 if (intermission_running)
1269                 {
1270                         IntermissionThink ();   // otherwise a button could be missed between
1271                         return;                                 // the think tics
1272                 }
1273
1274                 if(time > self.teleport_time)
1275                 {
1276                         self.effects = self.effects - (self.effects & EF_NODRAW);
1277                         if(self.weaponentity)
1278                                 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1279                 }
1280
1281                 Nixnex_GiveCurrentWeapon();
1282                 UpdateSelectedPlayer();
1283
1284                 if (self.deadflag != DEAD_NO)
1285                 {
1286                         float button_pressed, force_respawn;
1287                         player_anim();
1288                         button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1289                         force_respawn = (cvar("g_lms") || cvar("g_forced_respawn"));
1290                         if (self.deadflag == DEAD_DYING)
1291                         {
1292                                 if(force_respawn)
1293                                         self.deadflag = DEAD_RESPAWNING;
1294                                 else if(!button_pressed)
1295                                         self.deadflag = DEAD_DEAD;
1296                         }
1297                         else if (self.deadflag == DEAD_DEAD)
1298                         {
1299                                 if(button_pressed)
1300                                         self.deadflag = DEAD_RESPAWNABLE;
1301                         }
1302                         else if (self.deadflag == DEAD_RESPAWNABLE)
1303                         {
1304                                 if(!button_pressed)
1305                                         self.deadflag = DEAD_RESPAWNING;
1306                         }
1307                         else if (self.deadflag == DEAD_RESPAWNING)
1308                         {
1309                                 if(time > self.death_time)
1310                                         respawn();
1311                         }
1312                         ShowRespawnCountdown();
1313                         return;
1314                 }
1315
1316                 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1317                 {
1318                         vector dist;
1319
1320                         // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1321                         dist = self.oldorigin - self.origin;
1322                         dist_z = 0;
1323                         self.lms_traveled_distance += fabs(vlen(dist));
1324
1325                         if(cvar("g_campaign"))
1326                         if(!campaign_bots_may_start)
1327                         {
1328                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1329                                 self.lms_traveled_distance = 0;
1330                         }
1331
1332                         if(time > self.lms_nextcheck)
1333                         {
1334                                 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1335                                 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1336                                 {
1337                                         centerprint(self, cvar_string("g_lms_campcheck_message"));
1338                                         // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1339                                         // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1340                                         Damage(self, self, self, bound(0, cvar("g_lms_campcheck_damage"), self.health + self.armorvalue * cvar("g_balance_armor_blockpercent") + 5), DEATH_CAMP, self.origin, '0 0 0');
1341                                 }
1342                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1343                                 self.lms_traveled_distance = 0;
1344                         }
1345                 }
1346
1347                 if (self.button5 && !self.hook.state)
1348                 {
1349                         if (!self.crouch)
1350                         {
1351                                 self.crouch = TRUE;
1352                                 self.view_ofs = PL_CROUCH_VIEW_OFS;
1353                                 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1354                         }
1355                 }
1356                 else
1357                 {
1358                         if (self.crouch)
1359                         {
1360                                 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1361                                 if (!trace_startsolid)
1362                                 {
1363                                         self.crouch = FALSE;
1364                                         self.view_ofs = PL_VIEW_OFS;
1365                                         setsize (self, PL_MIN, PL_MAX);
1366                                 }
1367                         }
1368                 }
1369
1370                 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
1371                         local string defaultmodel;
1372                         defaultmodel = cvar_string("sv_defaultplayermodel");
1373
1374                         if (defaultmodel != self.model)
1375                         {
1376                                 m1 = self.mins;
1377                                 m2 = self.maxs;
1378                                 setmodel_lod (self, defaultmodel);
1379                                 setsize (self, m1, m2);
1380                         }
1381
1382                         if (self.skin != cvar("sv_defaultplayerskin"))
1383                                 self.skin = cvar("sv_defaultplayerskin");
1384                 } else {
1385                         if (self.playermodel != self.model)
1386                         {
1387                                 self.playermodel = CheckPlayerModel(self.playermodel);
1388                                 m1 = self.mins;
1389                                 m2 = self.maxs;
1390                                 setmodel_lod (self, self.playermodel);
1391                                 setsize (self, m1, m2);
1392                         }
1393
1394                         if(teams_matter)
1395                         {
1396                                 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1397                                         self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1398                         }
1399                         else
1400                         {
1401                                 if (self.skin != stof(self.playerskin))
1402                                         self.skin = stof(self.playerskin);
1403                         }
1404                 }
1405
1406                 GrapplingHookFrame();
1407
1408                 W_WeaponFrame();
1409
1410                 {
1411                         float zoomfactor, zoomspeed, zoomdir;
1412                         zoomfactor = self.cvar_cl_zoomfactor;
1413                         if(zoomfactor < 1 || zoomfactor > 16)
1414                                 zoomfactor = 2.5;
1415                         zoomspeed = self.cvar_cl_zoomspeed;
1416                         if(zoomspeed >= 0) // < 0 is instant zoom
1417                                 if(zoomspeed < 0.5 || zoomspeed > 16)
1418                                         zoomspeed = 3.5;
1419
1420                         zoomdir = self.button4;
1421                         if(self.button3)
1422                                 if(self.weapon == WEP_NEX)
1423                                         if(!cvar("g_minstagib"))
1424                                                 zoomdir = 1;
1425
1426                         if(zoomdir)
1427                                 self.has_zoomed = 1;
1428
1429                         if(self.has_zoomed)
1430                         {
1431                                 if(zoomspeed <= 0) // instant zoom
1432                                 {
1433                                         if(zoomdir)
1434                                                 self.viewzoom = 1 / zoomfactor;
1435                                         else
1436                                                 self.viewzoom = 1;
1437                                 }
1438                                 else
1439                                 {
1440                                         // geometric zoom would be:
1441                                         //   self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1442                                         // however, testing showed that arithmetic/harmonic zoom works better
1443                                         if(zoomdir)
1444                                                 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1445                                                 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1446                                                 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1447                                         else
1448                                                 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1449                                                 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1450                                                 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1451                                 }
1452                         }
1453                         else
1454                                 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1455                 }
1456
1457                 player_powerups();
1458                 player_regen();
1459                 player_anim();
1460
1461                 if (cvar("g_minstagib"))
1462                         minstagib_ammocheck();
1463
1464                 ctf_setstatus();
1465                 kh_setstatus();
1466
1467                 //self.angles_y=self.v_angle_y + 90;   // temp
1468
1469                 //if (TetrisPreFrame()) return;
1470         } else if(gameover) {
1471                 if (intermission_running)
1472                         IntermissionThink ();   // otherwise a button could be missed between
1473                 return;
1474         } else if(self.classname == "observer") {
1475
1476                 if (self.flags & FL_JUMPRELEASED) {
1477                         if (self.button2 && self.version == cvar("gameversion")) {
1478                                 self.welcomemessage_time = 0;
1479                                 self.flags = self.flags - FL_JUMPRELEASED;
1480                                 LeaveSpectatorMode();
1481                                 return;
1482                         } else if(self.button0 && self.version == cvar("gameversion")) {
1483                                 self.welcomemessage_time = 0;
1484                                 self.flags = self.flags - FL_JUMPRELEASED;
1485                                 if(SpectateNext() == 1) {
1486                                         self.classname = "spectator";
1487                                 }
1488                         }
1489                 } else {
1490                         if (!(self.button0 || self.button2)) {
1491                                 self.flags = self.flags | FL_JUMPRELEASED;
1492                         }
1493                 }
1494                 PrintWelcomeMessage(self);
1495         } else if(self.classname == "spectator") {
1496                 if (self.flags & FL_JUMPRELEASED) {
1497                         if (self.button2 && self.version == cvar("gameversion")) {
1498                                 self.welcomemessage_time = 0;
1499                                 self.flags = self.flags - FL_JUMPRELEASED;
1500                                 LeaveSpectatorMode();
1501                                 return;
1502                         } else if(self.button0) {
1503                                 self.welcomemessage_time = 0;
1504                                 self.flags = self.flags - FL_JUMPRELEASED;
1505                                 if(SpectateNext() == 1) {
1506                                         self.classname = "spectator";
1507                                 } else {
1508                                         self.classname = "observer";
1509                                         PutClientInServer();
1510                                 }
1511                         } else if (self.button3) {
1512                                 self.welcomemessage_time = 0;
1513                                 self.flags = self.flags - FL_JUMPRELEASED;
1514                                 self.classname = "observer";
1515                                 PutClientInServer();
1516                         } else {
1517                                 SpectateUpdate();
1518                         }
1519                 } else {
1520                         if (!(self.button0 || self.button3)) {
1521                                 self.flags = self.flags | FL_JUMPRELEASED;
1522                         }
1523                 }
1524                 PrintWelcomeMessage(self);
1525                 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1526         }
1527 }
1528
1529
1530 /*
1531 =============
1532 PlayerPostThink
1533
1534 Called every frame for each client after the physics are run
1535 =============
1536 */
1537 void PlayerPostThink (void)
1538 {
1539         // Savage: Check for nameless players
1540         if (strlen(self.netname) < 1) {
1541                 self.netname = "Player";
1542                 stuffcmd(self, "seta _cl_name Player\n");
1543         }
1544
1545         if(self.classname == "player") {
1546                 CheckRules_Player();
1547                 UpdateChatBubble();
1548                 UpdateTeamBubble();
1549                 if (self.impulse)
1550                         ImpulseCommands ();
1551                 if (intermission_running)
1552                         return;         // intermission or finale
1553
1554                 //PrintWelcomeMessage(self);
1555                 //if (TetrisPostFrame()) return;
1556         } else if (self.classname == "observer") {
1557                 //do nothing
1558         } else if (self.classname == "spectator") {
1559                 //do nothing
1560         }
1561         Arena_Warmup();
1562 }