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