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