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