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