]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/cl_client.qc
make use of DP_CON_BESTWEAPON to make the bestweapon command actually work
[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) {
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                         {
501                                 float s;
502                                 s = stof(self.playerskin);
503                                 if(s >= 0 && s < 3)
504                                         self.skin = s;
505                                 else if(s == 6)
506                                         self.skin = 6;
507                                 else
508                                         self.skin = 0;
509                         }
510                         else
511                                 self.skin = stof(self.playerskin);
512                 }
513                 if(!teams_matter)
514                         if(strlen(cvar_string("sv_defaultplayercolors")))
515                                 setcolor(self, cvar("sv_defaultplayercolors"));
516
517                 self.crouch = FALSE;
518                 self.view_ofs = PL_VIEW_OFS;
519                 setsize (self, PL_MIN, PL_MAX);
520                 self.spawnorigin = spot.origin;
521                 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
522                 // don't reset back to last position, even if new position is stuck in solid
523                 self.oldorigin = self.origin;
524
525                 if(cvar("g_arena"))
526                 {
527                         Spawnqueue_Remove(self);
528                         Spawnqueue_Mark(self);
529                 }
530
531                 self.event_damage = PlayerDamage;
532
533                 self.bot_attack = TRUE;
534
535                 self.statdraintime = time + 5;
536                 self.button0 = self.button1 = self.button2 = self.button3 = 0;
537
538                 if(self.killcount == -666) {
539                         self.killcount = 0;
540                         if(!cvar("g_arena"))
541                         if(!cvar("g_lms"))
542                                 self.frags = 0;
543                 }
544
545                 self.cnt = WEP_LASER;
546                 self.nixnex_lastchange_id = -1;
547
548                 CL_SpawnWeaponentity();
549                 self.alpha = default_player_alpha;
550                 self.exteriorweaponentity.alpha = default_weapon_alpha;
551
552                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
553                 self.lms_traveled_distance = 0;
554
555                 if(cvar("spawn_debug"))
556                 {
557                         sprint(self, strcat("spawnpoint origin:  ", vtos(spot.origin), "\n"));
558                         remove(spot);   // usefull for checking if there are spawnpoints, that let drop through the floor
559                 }
560
561                 //stuffcmd(self, "chase_active 0");
562                 //stuffcmd(self, "set viewsize $tmpviewsize \n");
563
564                 if (cvar("g_spawnsound"))
565                         sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
566
567                 if(cvar("g_assault")) {
568                         if(self.team == assault_attacker_team)
569                                 centerprint(self, "You are attacking!\n");
570                         else
571                                 centerprint(self, "You are defending!\n");
572                 }
573
574         } else if(self.classname == "observer") {
575                 PutObserverInServer ();
576         }
577 }
578
579 /*
580 =============
581 SetNewParms
582 =============
583 */
584 void SetNewParms (void)
585 {
586
587 }
588
589 /*
590 =============
591 SetChangeParms
592 =============
593 */
594 void SetChangeParms (void)
595 {
596
597 }
598
599 /*
600 =============
601 ClientKill
602
603 Called when a client types 'kill' in the console
604 =============
605 */
606 void ClientKill (void)
607 {
608         Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
609 }
610
611 void FixClientCvars(entity e)
612 {
613         // send prediction settings to the client
614         stuffcmd(e, "\nin_bindmap 0 0\n");
615         stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
616         stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
617         stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
618         stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
619         stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
620         stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
621         stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
622         stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
623         stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
624         stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
625         stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
626         stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
627         stuffcmd(e, "cl_movement_edgefriction 1\n");
628 }
629
630 /*
631 =============
632 ClientConnect
633
634 Called when a client connects to the server
635 =============
636 */
637 string ColoredTeamName(float t);
638 //void dom_player_join_team(entity pl);
639 void ClientConnect (void)
640 {
641         local string s;
642         float wep;
643
644         if(Ban_IsClientBanned(self))
645         {
646                 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
647                 dropclient(self);
648                 bprint(s);
649                 return;
650         }
651
652         self.classname = "player_joining";
653         self.flags = self.flags | FL_CLIENT;
654         self.version_nagtime = time + 10 + random() * 10;
655
656         if(player_count<0)
657         {
658                 dprint("BUG player count is lower than zero, this cannot happen!\n");
659                 player_count = 0;
660         }
661
662         bot_clientconnect();
663
664         //if(cvar("g_domination"))
665         //      dom_player_join_team(self);
666
667         //JoinBestTeam(self, FALSE);
668
669         if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
670                 self.classname = "observer";
671         } else {
672                 self.classname = "player";
673                 campaign_bots_may_start = 1;
674         }
675
676         self.playerid = (playerid_last = playerid_last + 1);
677         if(cvar("sv_eventlog"))
678         {
679                 if(clienttype(self) == CLIENTTYPE_REAL)
680                         s = "player";
681                 else
682                         s = "bot";
683                 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
684                 s = strcat(":team:", ftos(self.playerid), ":");
685                 s = strcat(s, ftos(self.team));
686                 GameLogEcho(s, FALSE);
687         }
688
689         //stuffcmd(self, "set tmpviewsize $viewsize \n");
690
691         bprint ("^4",self.netname);
692         bprint ("^4 connected");
693
694         if(cvar("g_domination") || cvar("g_ctf"))
695         {
696                 bprint(" and joined the ");
697                 bprint(ColoredTeamName(self.team));
698         }
699
700         bprint("\n");
701
702         self.welcomemessage_time = 0;
703
704         stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
705         // TODO: is this being used for anything else than cd tracks?
706         // Remember: SVC_CDTRACK exists. Maybe it should be used.
707
708         FixClientCvars(self);
709
710         // waypoint sprites
711         WaypointSprite_InitClient(self);
712
713         // Wazat's grappling hook
714         SetGrappleHookBindings();
715
716         // get autoswitch state from player when he toggles it
717         stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
718
719         // get version info from player
720         stuffcmd(self, "cmd clientversion $gameversion\n");
721
722         // send all weapon info strings
723         stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
724         wep = WEP_FIRST;
725         while (wep <= WEP_LAST)
726         {
727                 weapon_action(wep, WR_REGISTER);
728                 wep = wep + 1;
729         }
730
731         // get other cvars from player
732         GetCvars(0);
733
734         // set cvar for team scoreboard
735         if (teams_matter)
736         {
737                 local float t;
738                 t = cvar("teamplay");
739                 // 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
740                 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
741         }
742         else
743                 stuffcmd(self, "set teamplay 0\n");
744
745         if(cvar("g_lms"))
746         {
747                 self.frags = cvar("fraglimit");
748                 // no fraglimit was set, so player gets 999 lives
749                 if(self.frags < 1)
750                         self.frags = 999;
751
752                 self.frags = LMS_NewPlayerLives();
753                 if(!self.frags)
754                 {
755                         self.frags = -666;
756                 }
757         }
758         else if(cvar("g_arena"))
759         {
760                 self.classname = "observer";
761                 Spawnqueue_Insert(self);
762         }
763
764         bot_relinkplayerlist();
765
766         self.jointime = time;
767 }
768
769 /*
770 =============
771 ClientDisconnect
772
773 Called when a client disconnects from the server
774 =============
775 */
776 void(entity e) DropFlag;
777 .entity chatbubbleentity;
778 .entity teambubbleentity;
779 void ClientDisconnect (void)
780 {
781         float save;
782         if(cvar("sv_eventlog"))
783                 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
784         bprint ("^4",self.netname);
785         bprint ("^4 disconnected\n");
786
787         if (self.chatbubbleentity)
788         {
789                 remove (self.chatbubbleentity);
790                 self.chatbubbleentity = world;
791         }
792
793         if (self.teambubbleentity)
794         {
795                 remove (self.teambubbleentity);
796                 self.teambubbleentity = world;
797         }
798
799         WaypointSprite_PlayerGone();
800
801         DropAllRunes(self);
802         kh_Key_DropAll(self, TRUE);
803
804         if(self.flagcarried)
805                 DropFlag(self.flagcarried);
806
807         DistributeFragsAmongTeam(self, self.team, 1);
808
809         save = self.flags;
810         self.flags = self.flags - (self.flags & FL_CLIENT);
811         bot_relinkplayerlist();
812         self.flags = save;
813
814         // remove laserdot
815         if(self.weaponentity)
816                 if(self.weaponentity.lasertarget)
817                         remove(self.weaponentity.lasertarget);
818
819         if(cvar("g_arena"))
820         {
821                 Spawnqueue_Unmark(self);
822                 Spawnqueue_Remove(self);
823         }
824
825         // free cvars
826         GetCvars(-1);
827 }
828
829 .float buttonchat;
830 void() ChatBubbleThink =
831 {
832         self.nextthink = time;
833         if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
834         {
835                 self.owner.chatbubbleentity = world;
836                 remove(self);
837                 return;
838         }
839         setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
840         if (self.owner.buttonchat && !self.owner.deadflag)
841                 self.model = self.mdl;
842         else
843                 self.model = "";
844 };
845
846 void() UpdateChatBubble =
847 {
848         if (!self.modelindex)
849                 return;
850         // spawn a chatbubble entity if needed
851         if (!self.chatbubbleentity)
852         {
853                 self.chatbubbleentity = spawn();
854                 self.chatbubbleentity.owner = self;
855                 self.chatbubbleentity.exteriormodeltoclient = self;
856                 self.chatbubbleentity.think = ChatBubbleThink;
857                 self.chatbubbleentity.nextthink = time;
858                 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
859                 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
860                 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
861                 self.chatbubbleentity.model = "";
862                 self.chatbubbleentity.effects = EF_LOWPRECISION;
863         }
864 }
865
866
867 void() TeamBubbleThink =
868 {
869         self.nextthink = time;
870         if (!self.owner.modelindex || self.owner.teambubbleentity != self)
871         {
872                 self.owner.teambubbleentity = world;
873                 remove(self);
874                 return;
875         }
876 //      setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');  // bandwidth hog. setattachment does this now
877         if (self.owner.buttonchat || self.owner.deadflag)
878                 self.model = "";
879         else
880                 self.model = self.mdl;
881
882 };
883
884 float() TeamBubble_customizeentityforclient
885 {
886         return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
887 }
888
889 void() UpdateTeamBubble =
890 {
891         if (!self.modelindex || !cvar("teamplay"))
892                 return;
893         // spawn a teambubble entity if needed
894         if (!self.teambubbleentity && cvar("teamplay"))
895         {
896                 self.teambubbleentity = spawn();
897                 self.teambubbleentity.owner = self;
898                 self.teambubbleentity.exteriormodeltoclient = self;
899                 self.teambubbleentity.think = TeamBubbleThink;
900                 self.teambubbleentity.nextthink = time;
901                 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
902 //              setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
903                 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
904                 setattachment(self.teambubbleentity, self, "");  // sticks to moving player better, also conserves bandwidth
905                 self.teambubbleentity.mdl = self.teambubbleentity.model;
906                 self.teambubbleentity.model = self.teambubbleentity.mdl;
907                 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
908                 self.teambubbleentity.effects = EF_LOWPRECISION;
909         }
910 }
911
912 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
913 // added to the model skins
914 /*void() UpdateColorModHack =
915 {
916         local float c;
917         c = self.clientcolors & 15;
918         // LordHavoc: only bothering to support white, green, red, yellow, blue
919              if (teamplay == 0) self.colormod = '0 0 0';
920         else if (c ==  0) self.colormod = '1.00 1.00 1.00';
921         else if (c ==  3) self.colormod = '0.10 1.73 0.10';
922         else if (c ==  4) self.colormod = '1.73 0.10 0.10';
923         else if (c == 12) self.colormod = '1.22 1.22 0.10';
924         else if (c == 13) self.colormod = '0.10 0.10 1.73';
925         else self.colormod = '1 1 1';
926 };*/
927
928 void respawn(void)
929 {
930         CopyBody(1);
931         PutClientInServer();
932 }
933
934 void player_powerups (void)
935 {
936         if (cvar("g_minstagib"))
937         {
938                 self.effects = EF_FULLBRIGHT;
939                 if (self.items & IT_STRENGTH)
940                 {
941                         if (time > self.strength_finished)
942                         {
943                                 self.alpha = default_player_alpha;
944                                 self.exteriorweaponentity.alpha = default_weapon_alpha;
945                                 self.items = self.items - (self.items & IT_STRENGTH);
946                                 sprint(self, "^3Invisibility has worn off\n");
947                         }
948                 }
949                 else
950                 {
951                         if (time < self.strength_finished)
952                         {
953                                 self.alpha = cvar("g_minstagib_invis_alpha");
954                                 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
955                                 self.items = self.items | IT_STRENGTH;
956                                 sprint(self, "^3You are invisible\n");
957                         }
958                 }
959
960                 if (self.items & IT_INVINCIBLE)
961                 {
962                         if (time > self.invincible_finished)
963                         {
964                                 self.items = self.items - (self.items & IT_INVINCIBLE);
965                                 sprint(self, "^3Speed has worn off\n");
966                         }
967                 }
968                 else
969                 {
970                         if (time < self.invincible_finished)
971                         {
972                                 self.items = self.items | IT_INVINCIBLE;
973                                 sprint(self, "^3You are on speed\n");
974                         }
975                 }
976                 return;
977         }
978
979         self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
980         if (self.items & IT_STRENGTH)
981         {
982                 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
983                 if (time > self.strength_finished)
984                 {
985                         self.items = self.items - (self.items & IT_STRENGTH);
986                         sprint(self, "^3Strength has worn off\n");
987                 }
988         }
989         else
990         {
991                 if (time < self.strength_finished)
992                 {
993                         self.items = self.items | IT_STRENGTH;
994                         sprint(self, "^3Strength infuses your weapons with devastating power\n");
995                 }
996         }
997         if (self.items & IT_INVINCIBLE)
998         {
999                 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1000                 if (time > self.invincible_finished)
1001                 {
1002                         self.items = self.items - (self.items & IT_INVINCIBLE);
1003                         sprint(self, "^3Shield has worn off\n");
1004                 }
1005         }
1006         else
1007         {
1008                 if (time < self.invincible_finished)
1009                 {
1010                         self.items = self.items | IT_INVINCIBLE;
1011                         sprint(self, "^3Shield surrounds you\n");
1012                 }
1013         }
1014
1015         if (cvar("g_fullbrightplayers"))
1016                 self.effects = self.effects | EF_FULLBRIGHT;
1017
1018         // midair gamemode: damage only while in the air
1019         // if in midair mode, being on ground grants temporary invulnerability
1020         // (this is so that multishot weapon don't clear the ground flag on the
1021         // first damage in the frame, leaving the player vulnerable to the
1022         // remaining hits in the same frame)
1023         if (self.flags & FL_ONGROUND)
1024         if (cvar("g_midair"))
1025                 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1026
1027         if (time < self.spawnshieldtime)
1028                 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1029 }
1030
1031 float CalcRegen(float current, float stable, float regenfactor)
1032 {
1033         if(current > stable)
1034                 return current;
1035         else if(current > stable - 0.25) // when close enough, "snap"
1036                 return stable;
1037         else
1038                 return min(stable, current + (stable - current) * regenfactor * frametime);
1039 }
1040
1041 void player_regen (void)
1042 {
1043         float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1044         maxh = cvar("g_balance_health_stable");
1045         maxa = cvar("g_balance_armor_stable");
1046         limith = cvar("g_balance_health_limit");
1047         limita = cvar("g_balance_armor_limit");
1048
1049         if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
1050                 return;
1051
1052         max_mod = regen_mod = rot_mod = limit_mod = 1;
1053
1054         if (self.runes & RUNE_REGEN)
1055         {
1056                 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1057                 {
1058                         regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1059                         max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1060                         limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1061                 }
1062                 else
1063                 {
1064                         regen_mod = cvar("g_balance_rune_regen_regenrate");
1065                         max_mod = cvar("g_balance_rune_regen_hpmod");
1066                         limit_mod = cvar("g_balance_rune_regen_limitmod");
1067                 }
1068         }
1069         else if (self.runes & CURSE_VENOM)
1070         {
1071                 max_mod = cvar("g_balance_curse_venom_hpmod");
1072                 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1073                         rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1074                 else
1075                         rot_mod = cvar("g_balance_curse_venom_rotrate");
1076                 limit_mod = cvar("g_balance_curse_venom_limitmod");
1077                 //if (!self.runes & RUNE_REGEN)
1078                 //      rot_mod = cvar("g_balance_curse_venom_rotrate");
1079         }
1080         maxh = maxh * max_mod;
1081         //maxa = maxa * max_mod;
1082         limith = limith * limit_mod;
1083         limita = limita * limit_mod;
1084
1085         if (self.armorvalue > maxa)
1086         {
1087                 if (time > self.pauserotarmor_finished)
1088                 {
1089                         self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1090                         self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1091                 }
1092         }
1093         else if (self.armorvalue < maxa)
1094         {
1095                 if (time > self.pauseregen_finished)
1096                 {
1097                         self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1098                         self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1099                 }
1100         }
1101         if (self.health > maxh)
1102         {
1103                 if (time > self.pauserothealth_finished)
1104                 {
1105                         self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1106                         self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1107                 }
1108         }
1109         else if (self.health < maxh)
1110         {
1111                 if (time > self.pauseregen_finished)
1112                 {
1113                         self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1114                         self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1115                 }
1116         }
1117
1118         if (self.health > limith)
1119                 self.health = limith;
1120         if (self.armorvalue > limita)
1121                 self.armorvalue = limita;
1122
1123         // if player rotted to death...  die!
1124         if(self.health < 1)
1125                 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1126 }
1127
1128 /*
1129 ======================
1130 spectate mode routines
1131 ======================
1132 */
1133 void SpectateCopy(entity spectatee) {
1134         self.armortype = spectatee.armortype;
1135         self.armorvalue = spectatee.armorvalue;
1136         self.currentammo = spectatee.currentammo;
1137         self.effects = spectatee.effects;
1138         self.health = spectatee.health;
1139         self.impulse = 0;
1140         self.items = spectatee.items;
1141         self.punchangle = spectatee.punchangle;
1142         self.view_ofs = spectatee.view_ofs;
1143         self.v_angle = spectatee.v_angle;
1144         self.viewzoom = spectatee.viewzoom;
1145         setorigin(self, spectatee.origin);
1146         setsize(self, spectatee.mins, spectatee.maxs);
1147 }
1148
1149 void SpectateUpdate() {
1150         if(!self.enemy)
1151                         PutObserverInServer();
1152
1153         if (self != self.enemy) {
1154                 if(self.enemy.flags & FL_NOTARGET)
1155                         PutObserverInServer();
1156                 SpectateCopy(self.enemy);
1157                 self.dmg_take = self.enemy.dmg_take;
1158                 self.dmg_save = self.enemy.dmg_save;
1159                 self.dmg_inflictor = self.enemy.dmg_inflictor;
1160                 self.fixangle = TRUE;
1161                 self.angles = self.enemy.v_angle;
1162                 //msg_entity = self;
1163                 //WriteByte(MSG_ONE, SVC_SETANGLE);
1164                 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1165                 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1166                 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1167         }
1168 }
1169
1170 float SpectateNext() {
1171         other = find(self.enemy, classname, "player");
1172         if (!other) {
1173                 other = find(other, classname, "player");
1174         }
1175         if (other) {
1176                 self.enemy = other;
1177         }
1178         if(self.enemy.classname == "player") {
1179                 msg_entity = self;
1180                 WriteByte(MSG_ONE, SVC_SETVIEW);
1181                 WriteEntity(MSG_ONE, self.enemy);
1182                 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1183                 SpectateUpdate();
1184                 return 1;
1185         } else {
1186                 return 0;
1187         }
1188 }
1189
1190 /*
1191 =============
1192 ShowRespawnCountdown()
1193
1194 Update a respawn countdown display.
1195 =============
1196 */
1197 void ShowRespawnCountdown()
1198 {
1199         float number;
1200         if(self.deadflag == DEAD_NO) // just respawned?
1201                 return;
1202         else
1203         {
1204                 number = ceil(self.death_time - time);
1205                 if(number <= 0)
1206                         return;
1207                 if(number <= self.respawn_countdown)
1208                 {
1209                         self.respawn_countdown = number - 1;
1210                         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
1211                                 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1212                 }
1213         }
1214 }
1215
1216 void LeaveSpectatorMode()
1217 {
1218         if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1219                 self.classname = "player";
1220                 if(cvar("g_campaign") || cvar("g_balance_teams"))
1221                         JoinBestTeam(self, 0);
1222                 if(cvar("g_campaign"))
1223                         campaign_bots_may_start = 1;
1224                 PutClientInServer();
1225                 if(!(self.flags & FL_NOTARGET))
1226                         bprint ("^4", self.netname, "^4 is playing now\n");
1227                 centerprint(self,"");
1228                 return;
1229         } else {
1230                 stuffcmd(self,"menu_showteamselect\n");
1231                 return;
1232         }
1233 }
1234
1235 /*
1236 =============
1237 PlayerPreThink
1238
1239 Called every frame for each client before the physics are run
1240 =============
1241 */
1242 void() ctf_setstatus;
1243 .float vote_nagtime;
1244 void PlayerPreThink (void)
1245 {
1246         // version nagging
1247         if(self.version_nagtime)
1248                 if(self.cvar_g_nexuizversion)
1249                         if(time > self.version_nagtime)
1250                         {
1251                                 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1252                                         if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1253                                         {
1254                                                 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");
1255                                                 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1256                                         }
1257                                 self.version_nagtime = 0;
1258                         }
1259
1260         // vote nagging
1261         if(self.cvar_scr_centertime)
1262                 if(time > self.vote_nagtime)
1263                 {
1264                         VoteNag();
1265                         self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1266                 }
1267
1268         // GOD MODE info
1269         if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1270         {
1271                 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1272                 self.max_armorvalue = 0;
1273         }
1274
1275         if(self.classname == "player") {
1276                 local vector m1, m2;
1277
1278 //              if(self.netname == "Wazat")
1279 //                      bprint(self.classname, "\n");
1280
1281                 CheckRules_Player();
1282
1283                 if(self.button7)
1284                         PrintWelcomeMessage(self);
1285
1286                 if(cvar("g_lms") || !cvar("sv_spectate"))
1287                 if((time - self.jointime) <= cvar("welcome_message_time"))
1288                         PrintWelcomeMessage(self);
1289
1290                 if (intermission_running)
1291                 {
1292                         IntermissionThink ();   // otherwise a button could be missed between
1293                         return;                                 // the think tics
1294                 }
1295
1296                 if(time > self.teleport_time)
1297                 {
1298                         self.effects = self.effects - (self.effects & EF_NODRAW);
1299                         if(self.weaponentity)
1300                                 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1301                 }
1302
1303                 Nixnex_GiveCurrentWeapon();
1304                 UpdateSelectedPlayer();
1305
1306                 if (self.deadflag != DEAD_NO)
1307                 {
1308                         float button_pressed, force_respawn;
1309                         player_anim();
1310                         button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1311                         force_respawn = (cvar("g_lms") || cvar("g_forced_respawn"));
1312                         if (self.deadflag == DEAD_DYING)
1313                         {
1314                                 if(force_respawn)
1315                                         self.deadflag = DEAD_RESPAWNING;
1316                                 else if(!button_pressed)
1317                                         self.deadflag = DEAD_DEAD;
1318                         }
1319                         else if (self.deadflag == DEAD_DEAD)
1320                         {
1321                                 if(button_pressed)
1322                                         self.deadflag = DEAD_RESPAWNABLE;
1323                         }
1324                         else if (self.deadflag == DEAD_RESPAWNABLE)
1325                         {
1326                                 if(!button_pressed)
1327                                         self.deadflag = DEAD_RESPAWNING;
1328                         }
1329                         else if (self.deadflag == DEAD_RESPAWNING)
1330                         {
1331                                 if(time > self.death_time)
1332                                         respawn();
1333                         }
1334                         ShowRespawnCountdown();
1335                         return;
1336                 }
1337
1338                 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1339                 {
1340                         vector dist;
1341
1342                         // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1343                         dist = self.oldorigin - self.origin;
1344                         dist_z = 0;
1345                         self.lms_traveled_distance += fabs(vlen(dist));
1346
1347                         if(cvar("g_campaign"))
1348                         if(!campaign_bots_may_start)
1349                         {
1350                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1351                                 self.lms_traveled_distance = 0;
1352                         }
1353
1354                         if(time > self.lms_nextcheck)
1355                         {
1356                                 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1357                                 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1358                                 {
1359                                         centerprint(self, cvar_string("g_lms_campcheck_message"));
1360                                         // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1361                                         // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1362                                         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');
1363                                 }
1364                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1365                                 self.lms_traveled_distance = 0;
1366                         }
1367                 }
1368
1369                 if (self.button5 && !self.hook.state)
1370                 {
1371                         if (!self.crouch)
1372                         {
1373                                 self.crouch = TRUE;
1374                                 self.view_ofs = PL_CROUCH_VIEW_OFS;
1375                                 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1376                         }
1377                 }
1378                 else
1379                 {
1380                         if (self.crouch)
1381                         {
1382                                 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1383                                 if (!trace_startsolid)
1384                                 {
1385                                         self.crouch = FALSE;
1386                                         self.view_ofs = PL_VIEW_OFS;
1387                                         setsize (self, PL_MIN, PL_MAX);
1388                                 }
1389                         }
1390                 }
1391
1392                 if(cvar("sv_defaultcharacter") == 1) {
1393                         local string defaultmodel;
1394                         defaultmodel = cvar_string("sv_defaultplayermodel");
1395
1396                         if (defaultmodel != self.model)
1397                         {
1398                                 m1 = self.mins;
1399                                 m2 = self.maxs;
1400                                 setmodel_lod (self, defaultmodel);
1401                                 setsize (self, m1, m2);
1402                         }
1403
1404                         if (self.skin != cvar("sv_defaultplayerskin"))
1405                                 self.skin = cvar("sv_defaultplayerskin");
1406                 } else {
1407                         if (self.playermodel != self.model)
1408                         {
1409                                 self.playermodel = CheckPlayerModel(self.playermodel);
1410                                 m1 = self.mins;
1411                                 m2 = self.maxs;
1412                                 setmodel_lod (self, self.playermodel);
1413                                 setsize (self, m1, m2);
1414                         }
1415
1416                         if(teams_matter)
1417                         {
1418                                 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1419                                         self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1420                         }
1421                         else
1422                         {
1423                                 if (self.skin != stof(self.playerskin))
1424                                         self.skin = stof(self.playerskin);
1425                         }
1426                 }
1427                 if(!teams_matter)
1428                         if(strlen(cvar_string("sv_defaultplayercolors")))
1429                                 if(self.clientcolors != cvar("sv_defaultplayercolors"))
1430                                         setcolor(self, cvar("sv_defaultplayercolors"));
1431
1432                 GrapplingHookFrame();
1433
1434                 W_WeaponFrame();
1435
1436                 {
1437                         float zoomfactor, zoomspeed, zoomdir;
1438                         zoomfactor = self.cvar_cl_zoomfactor;
1439                         if(zoomfactor < 1 || zoomfactor > 16)
1440                                 zoomfactor = 2.5;
1441                         zoomspeed = self.cvar_cl_zoomspeed;
1442                         if(zoomspeed >= 0) // < 0 is instant zoom
1443                                 if(zoomspeed < 0.5 || zoomspeed > 16)
1444                                         zoomspeed = 3.5;
1445
1446                         zoomdir = self.button4;
1447                         if(self.button3)
1448                                 if(self.weapon == WEP_NEX)
1449                                         if(!cvar("g_minstagib"))
1450                                                 zoomdir = 1;
1451
1452                         if(zoomdir)
1453                                 self.has_zoomed = 1;
1454
1455                         if(self.has_zoomed)
1456                         {
1457                                 if(zoomspeed <= 0) // instant zoom
1458                                 {
1459                                         if(zoomdir)
1460                                                 self.viewzoom = 1 / zoomfactor;
1461                                         else
1462                                                 self.viewzoom = 1;
1463                                 }
1464                                 else
1465                                 {
1466                                         // geometric zoom would be:
1467                                         //   self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1468                                         // however, testing showed that arithmetic/harmonic zoom works better
1469                                         if(zoomdir)
1470                                                 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1471                                                 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1472                                                 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1473                                         else
1474                                                 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1475                                                 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1476                                                 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1477                                 }
1478                         }
1479                         else
1480                                 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1481                 }
1482
1483                 player_powerups();
1484                 player_regen();
1485                 player_anim();
1486
1487                 if (cvar("g_minstagib"))
1488                         minstagib_ammocheck();
1489
1490                 ctf_setstatus();
1491                 kh_setstatus();
1492
1493                 //self.angles_y=self.v_angle_y + 90;   // temp
1494
1495                 //if (TetrisPreFrame()) return;
1496         } else if(gameover) {
1497                 if (intermission_running)
1498                         IntermissionThink ();   // otherwise a button could be missed between
1499                 return;
1500         } else if(self.classname == "observer") {
1501
1502                 if (self.flags & FL_JUMPRELEASED) {
1503                         if (self.button2 && self.version == cvar("gameversion")) {
1504                                 self.welcomemessage_time = 0;
1505                                 self.flags = self.flags - FL_JUMPRELEASED;
1506                                 LeaveSpectatorMode();
1507                                 return;
1508                         } else if(self.button0 && self.version == cvar("gameversion")) {
1509                                 self.welcomemessage_time = 0;
1510                                 self.flags = self.flags - FL_JUMPRELEASED;
1511                                 if(SpectateNext() == 1) {
1512                                         self.classname = "spectator";
1513                                 }
1514                         }
1515                 } else {
1516                         if (!(self.button0 || self.button2)) {
1517                                 self.flags = self.flags | FL_JUMPRELEASED;
1518                         }
1519                 }
1520                 PrintWelcomeMessage(self);
1521         } else if(self.classname == "spectator") {
1522                 if (self.flags & FL_JUMPRELEASED) {
1523                         if (self.button2 && self.version == cvar("gameversion")) {
1524                                 self.welcomemessage_time = 0;
1525                                 self.flags = self.flags - FL_JUMPRELEASED;
1526                                 LeaveSpectatorMode();
1527                                 return;
1528                         } else if(self.button0) {
1529                                 self.welcomemessage_time = 0;
1530                                 self.flags = self.flags - FL_JUMPRELEASED;
1531                                 if(SpectateNext() == 1) {
1532                                         self.classname = "spectator";
1533                                 } else {
1534                                         self.classname = "observer";
1535                                         PutClientInServer();
1536                                 }
1537                         } else if (self.button3) {
1538                                 self.welcomemessage_time = 0;
1539                                 self.flags = self.flags - FL_JUMPRELEASED;
1540                                 self.classname = "observer";
1541                                 PutClientInServer();
1542                         } else {
1543                                 SpectateUpdate();
1544                         }
1545                 } else {
1546                         if (!(self.button0 || self.button3)) {
1547                                 self.flags = self.flags | FL_JUMPRELEASED;
1548                         }
1549                 }
1550                 PrintWelcomeMessage(self);
1551                 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1552         }
1553 }
1554
1555
1556 /*
1557 =============
1558 PlayerPostThink
1559
1560 Called every frame for each client after the physics are run
1561 =============
1562 */
1563 void PlayerPostThink (void)
1564 {
1565         // Savage: Check for nameless players
1566         if (strlen(self.netname) < 1) {
1567                 self.netname = "Player";
1568                 stuffcmd(self, "seta _cl_name Player\n");
1569         }
1570
1571         if(self.classname == "player") {
1572                 CheckRules_Player();
1573                 UpdateChatBubble();
1574                 UpdateTeamBubble();
1575                 if (self.impulse)
1576                         ImpulseCommands ();
1577                 if (intermission_running)
1578                         return;         // intermission or finale
1579
1580                 //PrintWelcomeMessage(self);
1581                 //if (TetrisPostFrame()) return;
1582         } else if (self.classname == "observer") {
1583                 //do nothing
1584         } else if (self.classname == "spectator") {
1585                 //do nothing
1586         }
1587         Arena_Warmup();
1588 }