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