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