]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/cl_client.qc
very major cleanup of precache code, this patch reduced memory usage
[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                 sound (self, CHAN_AUTO, "misc/teleport.wav", 1, ATTN_NORM);
537         } else if(self.classname == "observer") {
538                 PutObserverInServer ();
539         }
540 }
541
542 /*
543 =============
544 SetNewParms
545 =============
546 */
547 void SetNewParms (void)
548 {
549
550 }
551
552 /*
553 =============
554 SetChangeParms
555 =============
556 */
557 void SetChangeParms (void)
558 {
559
560 }
561
562 /*
563 =============
564 ClientKill
565
566 Called when a client types 'kill' in the console
567 =============
568 */
569 void ClientKill (void)
570 {
571         Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
572 }
573
574 void FixClientCvars(entity e)
575 {
576         // send prediction settings to the client
577         stuffcmd(e, "\nin_bindmap 0 0\n");
578         stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
579         stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
580         stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
581         stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
582         stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
583         stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
584         stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
585         stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("g_balance_jumpheight")), "\n"));
586         stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
587         stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
588         stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
589         stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
590         stuffcmd(e, "cl_movement_edgefriction 1\n");
591 }
592
593 /*
594 =============
595 ClientConnect
596
597 Called when a client connects to the server
598 =============
599 */
600 string ColoredTeamName(float t);
601 //void dom_player_join_team(entity pl);
602 void ClientConnect (void)
603 {
604         local string s;
605
606         self.classname = "player_joining";
607         self.flags = self.flags | FL_CLIENT;
608         self.version_nagtime = time + 10 + random() * 10;
609
610         if(player_count<0)
611         {
612                 dprint("BUG player count is lower than zero, this cannot happen!\n");
613                 player_count = 0;
614         }
615
616         bot_clientconnect();
617
618         //if(cvar("g_domination"))
619         //      dom_player_join_team(self);
620
621         //JoinBestTeam(self, FALSE);
622
623         if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
624                 self.classname = "observer";
625         } else {
626                 self.classname = "player";
627                 campaign_bots_may_start = 1;
628         }
629
630         self.playerid = (playerid_last = playerid_last + 1);
631         if(cvar("sv_eventlog"))
632         {
633                 if(clienttype(self) == CLIENTTYPE_REAL)
634                         s = "player";
635                 else
636                         s = "bot";
637                 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
638                 s = strcat(":team:", ftos(self.playerid), ":");
639                 s = strcat(s, ftos(self.team));
640                 GameLogEcho(s, FALSE);
641         }
642
643         //stuffcmd(self, "set tmpviewsize $viewsize \n");
644
645         bprint ("^4",self.netname);
646         bprint ("^4 connected");
647
648         if(cvar("g_domination") || cvar("g_ctf"))
649         {
650                 bprint(" and joined the ");
651                 bprint(ColoredTeamName(self.team));
652         }
653
654         bprint("\n");
655
656         self.welcomemessage_time = 0;
657
658         stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
659         // TODO: is this being used for anything else than cd tracks?
660         // Remember: SVC_CDTRACK exists. Maybe it should be used.
661
662         FixClientCvars(self);
663
664         // waypoint sprites
665         WaypointSprite_InitClient(self);
666
667         // Wazat's grappling hook
668         SetGrappleHookBindings();
669
670         // get autoswitch state from player when he toggles it
671         stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
672
673         // get version info from player
674         stuffcmd(self, "cmd clientversion $gameversion\n");
675
676         // get other cvars from player
677         GetCvars(0);
678
679         // set cvar for team scoreboard
680         if (teams_matter)
681         {
682                 local float t;
683                 t = cvar("teamplay");
684                 // 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
685                 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
686         }
687         else
688                 stuffcmd(self, "set teamplay 0\n");
689
690         if(cvar("g_lms"))
691         {
692                 self.frags = cvar("fraglimit");
693                 // no fraglimit was set, so player gets 999 lives
694                 if(self.frags < 1)
695                         self.frags = 999;
696
697                 self.frags = LMS_NewPlayerLives();
698                 if(!self.frags)
699                 {
700                         self.frags = -666;
701                 }
702         }
703         else if(cvar("g_arena"))
704         {
705                 self.classname = "observer";
706                 Spawnqueue_Insert(self);
707         }
708
709         bot_relinkplayerlist();
710
711         self.jointime = time;
712 }
713
714 /*
715 =============
716 ClientDisconnect
717
718 Called when a client disconnects from the server
719 =============
720 */
721 void(entity e) DropFlag;
722 .entity chatbubbleentity;
723 .entity teambubbleentity;
724 void ClientDisconnect (void)
725 {
726         float save;
727         if(cvar("sv_eventlog"))
728                 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
729         bprint ("^4",self.netname);
730         bprint ("^4 disconnected\n");
731
732         if (self.chatbubbleentity)
733         {
734                 remove (self.chatbubbleentity);
735                 self.chatbubbleentity = world;
736         }
737
738         if (self.teambubbleentity)
739         {
740                 remove (self.teambubbleentity);
741                 self.teambubbleentity = world;
742         }
743
744         WaypointSprite_PlayerGone();
745
746         DropAllRunes(self);
747         kh_Key_DropAll(self);
748
749         if(self.flagcarried)
750                 DropFlag(self.flagcarried);
751
752         DistributeFragsAmongTeam(self, self.team, 1);
753
754         save = self.flags;
755         self.flags = self.flags - (self.flags & FL_CLIENT);
756         bot_relinkplayerlist();
757         self.flags = save;
758
759         // remove laserdot
760         if(self.weaponentity)
761                 if(self.weaponentity.lasertarget)
762                         remove(self.weaponentity.lasertarget);
763
764         if(cvar("g_arena"))
765         {
766                 Spawnqueue_Unmark(self);
767                 Spawnqueue_Remove(self);
768         }
769
770         // free cvars
771         GetCvars(-1);
772 }
773
774 .float buttonchat;
775 void() ChatBubbleThink =
776 {
777         self.nextthink = time;
778         if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
779         {
780                 self.owner.chatbubbleentity = world;
781                 remove(self);
782                 return;
783         }
784         setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
785         if (self.owner.buttonchat && !self.owner.deadflag)
786                 self.model = self.mdl;
787         else
788                 self.model = "";
789 };
790
791 void() UpdateChatBubble =
792 {
793         if (!self.modelindex)
794                 return;
795         // spawn a chatbubble entity if needed
796         if (!self.chatbubbleentity)
797         {
798                 self.chatbubbleentity = spawn();
799                 self.chatbubbleentity.owner = self;
800                 self.chatbubbleentity.exteriormodeltoclient = self;
801                 self.chatbubbleentity.think = ChatBubbleThink;
802                 self.chatbubbleentity.nextthink = time;
803                 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
804                 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
805                 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
806                 self.chatbubbleentity.model = "";
807                 self.chatbubbleentity.effects = EF_LOWPRECISION;
808         }
809 }
810
811
812 void() TeamBubbleThink =
813 {
814         self.nextthink = time;
815         if (!self.owner.modelindex || self.owner.teambubbleentity != self)
816         {
817                 self.owner.teambubbleentity = world;
818                 remove(self);
819                 return;
820         }
821 //      setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');  // bandwidth hog. setattachment does this now
822         if (self.owner.buttonchat || self.owner.deadflag)
823                 self.model = "";
824         else
825                 self.model = self.mdl;
826
827 };
828
829 float() TeamBubble_customizeentityforclient
830 {
831         return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
832 }
833
834 void() UpdateTeamBubble =
835 {
836         if (!self.modelindex || !cvar("teamplay"))
837                 return;
838         // spawn a teambubble entity if needed
839         if (!self.teambubbleentity && cvar("teamplay"))
840         {
841                 self.teambubbleentity = spawn();
842                 self.teambubbleentity.owner = self;
843                 self.teambubbleentity.exteriormodeltoclient = self;
844                 self.teambubbleentity.think = TeamBubbleThink;
845                 self.teambubbleentity.nextthink = time;
846                 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
847 //              setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
848                 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
849                 setattachment(self.teambubbleentity, self, "");  // sticks to moving player better, also conserves bandwidth
850                 self.teambubbleentity.mdl = self.teambubbleentity.model;
851                 self.teambubbleentity.model = self.teambubbleentity.mdl;
852                 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
853                 self.teambubbleentity.effects = EF_LOWPRECISION;
854         }
855 }
856
857 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
858 // added to the model skins
859 /*void() UpdateColorModHack =
860 {
861         local float c;
862         c = self.clientcolors & 15;
863         // LordHavoc: only bothering to support white, green, red, yellow, blue
864              if (teamplay == 0) self.colormod = '0 0 0';
865         else if (c ==  0) self.colormod = '1.00 1.00 1.00';
866         else if (c ==  3) self.colormod = '0.10 1.73 0.10';
867         else if (c ==  4) self.colormod = '1.73 0.10 0.10';
868         else if (c == 12) self.colormod = '1.22 1.22 0.10';
869         else if (c == 13) self.colormod = '0.10 0.10 1.73';
870         else self.colormod = '1 1 1';
871 };*/
872
873 void respawn(void)
874 {
875         CopyBody(1);
876         PutClientInServer();
877 }
878
879 void player_powerups (void)
880 {
881         if (cvar("g_minstagib"))
882         {
883                 self.effects = EF_FULLBRIGHT;
884                 if (self.items & IT_STRENGTH)
885                 {
886                         if (time > self.strength_finished)
887                         {
888                                 self.alpha = default_player_alpha;
889                                 self.exteriorweaponentity.alpha = default_weapon_alpha;
890                                 self.items = self.items - (self.items & IT_STRENGTH);
891                                 sprint(self, "^3Invisibility has worn off\n");
892                         }
893                 }
894                 else
895                 {
896                         if (time < self.strength_finished)
897                         {
898                                 self.alpha = cvar("g_minstagib_invis_alpha");
899                                 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
900                                 self.items = self.items | IT_STRENGTH;
901                                 sprint(self, "^3You are invisible\n");
902                         }
903                 }
904
905                 if (self.items & IT_INVINCIBLE)
906                 {
907                         if (time > self.invincible_finished)
908                         {
909                                 self.items = self.items - (self.items & IT_INVINCIBLE);
910                                 sprint(self, "^3Speed has worn off\n");
911                         }
912                 }
913                 else
914                 {
915                         if (time < self.invincible_finished)
916                         {
917                                 self.items = self.items | IT_INVINCIBLE;
918                                 sprint(self, "^3You are on speed\n");
919                         }
920                 }
921                 return;
922         }
923
924         self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
925         if (self.items & IT_STRENGTH)
926         {
927                 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
928                 if (time > self.strength_finished)
929                 {
930                         self.items = self.items - (self.items & IT_STRENGTH);
931                         sprint(self, "^3Strength has worn off\n");
932                 }
933         }
934         else
935         {
936                 if (time < self.strength_finished)
937                 {
938                         self.items = self.items | IT_STRENGTH;
939                         sprint(self, "^3Strength infuses your weapons with devastating power\n");
940                 }
941         }
942         if (self.items & IT_INVINCIBLE)
943         {
944                 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
945                 if (time > self.invincible_finished)
946                 {
947                         self.items = self.items - (self.items & IT_INVINCIBLE);
948                         sprint(self, "^3Shield has worn off\n");
949                 }
950         }
951         else
952         {
953                 if (time < self.invincible_finished)
954                 {
955                         self.items = self.items | IT_INVINCIBLE;
956                         sprint(self, "^3Shield surrounds you\n");
957                 }
958         }
959
960         if (cvar("g_fullbrightplayers"))
961                 self.effects = self.effects | EF_FULLBRIGHT;
962
963         // midair gamemode: damage only while in the air
964         // if in midair mode, being on ground grants temporary invulnerability
965         // (this is so that multishot weapon don't clear the ground flag on the
966         // first damage in the frame, leaving the player vulnerable to the
967         // remaining hits in the same frame)
968         if (self.flags & FL_ONGROUND)
969         if (cvar("g_midair"))
970                 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
971
972         if (time < self.spawnshieldtime)
973                 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
974 }
975
976 float CalcRegen(float current, float stable, float regenfactor)
977 {
978         if(current > stable)
979                 return current;
980         else if(current > stable - 0.25) // when close enough, "snap"
981                 return stable;
982         else
983                 return min(stable, current + (stable - current) * regenfactor * frametime);
984 }
985
986 void player_regen (void)
987 {
988         float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
989         maxh = cvar("g_balance_health_stable");
990         maxa = cvar("g_balance_armor_stable");
991         limith = cvar("g_balance_health_limit");
992         limita = cvar("g_balance_armor_limit");
993
994         if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
995                 return;
996
997         max_mod = regen_mod = rot_mod = limit_mod = 1;
998
999         if (self.runes & RUNE_REGEN)
1000         {
1001                 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1002                 {
1003                         regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1004                         max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1005                         limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1006                 }
1007                 else
1008                 {
1009                         regen_mod = cvar("g_balance_rune_regen_regenrate");
1010                         max_mod = cvar("g_balance_rune_regen_hpmod");
1011                         limit_mod = cvar("g_balance_rune_regen_limitmod");
1012                 }
1013         }
1014         else if (self.runes & CURSE_VENOM)
1015         {
1016                 max_mod = cvar("g_balance_curse_venom_hpmod");
1017                 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1018                         rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1019                 else
1020                         rot_mod = cvar("g_balance_curse_venom_rotrate");
1021                 limit_mod = cvar("g_balance_curse_venom_limitmod");
1022                 //if (!self.runes & RUNE_REGEN)
1023                 //      rot_mod = cvar("g_balance_curse_venom_rotrate");
1024         }
1025         maxh = maxh * max_mod;
1026         //maxa = maxa * max_mod;
1027         limith = limith * limit_mod;
1028         limita = limita * limit_mod;
1029
1030         if (self.armorvalue > maxa)
1031         {
1032                 if (time > self.pauserotarmor_finished)
1033                 {
1034                         self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1035                         self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1036                 }
1037         }
1038         else if (self.armorvalue < maxa)
1039         {
1040                 if (time > self.pauseregen_finished)
1041                 {
1042                         self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1043                         self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1044                 }
1045         }
1046         if (self.health > maxh)
1047         {
1048                 if (time > self.pauserothealth_finished)
1049                 {
1050                         self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1051                         self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1052                 }
1053         }
1054         else if (self.health < maxh)
1055         {
1056                 if (time > self.pauseregen_finished)
1057                 {
1058                         self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1059                         self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1060                 }
1061         }
1062
1063         if (self.health > limith)
1064                 self.health = limith;
1065         if (self.armorvalue > limita)
1066                 self.armorvalue = limita;
1067
1068         // if player rotted to death...  die!
1069         if(self.health < 1)
1070                 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1071 }
1072
1073 /*
1074 ======================
1075 spectate mode routines
1076 ======================
1077 */
1078 void SpectateCopy(entity spectatee) {
1079         self.armortype = spectatee.armortype;
1080         self.armorvalue = spectatee.armorvalue;
1081         self.currentammo = spectatee.currentammo;
1082         self.effects = spectatee.effects;
1083         self.health = spectatee.health;
1084         self.impulse = 0;
1085         self.items = spectatee.items;
1086         self.punchangle = spectatee.punchangle;
1087         self.view_ofs = spectatee.view_ofs;
1088         self.v_angle = spectatee.v_angle;
1089         self.viewzoom = spectatee.viewzoom;
1090         setorigin(self, spectatee.origin);
1091         setsize(self, spectatee.mins, spectatee.maxs);
1092 }
1093
1094 void SpectateUpdate() {
1095         if(!self.enemy)
1096                         PutObserverInServer();
1097
1098         if (self != self.enemy) {
1099                 if(self.enemy.flags & FL_NOTARGET)
1100                         PutObserverInServer();
1101                 SpectateCopy(self.enemy);
1102                 self.dmg_take = self.enemy.dmg_take;
1103                 self.dmg_save = self.enemy.dmg_save;
1104                 self.dmg_inflictor = self.enemy.dmg_inflictor;
1105                 self.fixangle = TRUE;
1106                 self.angles = self.enemy.v_angle;
1107                 //msg_entity = self;
1108                 //WriteByte(MSG_ONE, SVC_SETANGLE);
1109                 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1110                 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1111                 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1112         }
1113 }
1114
1115 float SpectateNext() {
1116         other = find(self.enemy, classname, "player");
1117         if (!other) {
1118                 other = find(other, classname, "player");
1119         }
1120         if (other) {
1121                 self.enemy = other;
1122         }
1123         if(self.enemy.classname == "player") {
1124                 msg_entity = self;
1125                 WriteByte(MSG_ONE, SVC_SETVIEW);
1126                 WriteEntity(MSG_ONE, self.enemy);
1127                 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1128                 SpectateUpdate();
1129                 return 1;
1130         } else {
1131                 return 0;
1132         }
1133 }
1134
1135 /*
1136 =============
1137 ShowRespawnCountdown()
1138
1139 Update a respawn countdown display.
1140 =============
1141 */
1142 void ShowRespawnCountdown()
1143 {
1144         float number;
1145         if(self.deadflag == DEAD_NO) // just respawned?
1146                 return;
1147         else
1148         {
1149                 number = ceil(self.death_time - time);
1150                 if(number <= 0)
1151                         return;
1152                 if(number <= self.respawn_countdown)
1153                 {
1154                         self.respawn_countdown = number - 1;
1155                         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
1156                                 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1157                 }
1158         }
1159 }
1160
1161 void LeaveSpectatorMode()
1162 {
1163         if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1164                 self.classname = "player";
1165                 if(cvar("g_campaign") || cvar("g_balance_teams"))
1166                         JoinBestTeam(self, 0);
1167                 if(cvar("g_campaign"))
1168                         campaign_bots_may_start = 1;
1169                 PutClientInServer();
1170                 if(!(self.flags & FL_NOTARGET))
1171                         bprint ("^4", self.netname, "^4 is playing now\n");
1172                 centerprint(self,"");
1173                 return;
1174         } else {
1175                 stuffcmd(self,"menu_showteamselect\n");
1176                 return;
1177         }
1178 }
1179
1180 /*
1181 =============
1182 PlayerPreThink
1183
1184 Called every frame for each client before the physics are run
1185 =============
1186 */
1187 void() ctf_setstatus;
1188 .float vote_nagtime;
1189 void PlayerPreThink (void)
1190 {
1191         // version nagging
1192         if(self.version_nagtime)
1193                 if(self.cvar_g_nexuizversion)
1194                         if(time > self.version_nagtime)
1195                         {
1196                                 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1197                                         if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1198                                         {
1199                                                 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");
1200                                                 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1201                                         }
1202                                 self.version_nagtime = 0;
1203                         }
1204
1205         // vote nagging
1206         if(self.cvar_scr_centertime)
1207                 if(time > self.vote_nagtime)
1208                 {
1209                         VoteNag();
1210                         self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1211                 }
1212
1213         if(self.classname == "player") {
1214                 local vector m1, m2;
1215
1216 //              if(self.netname == "Wazat")
1217 //                      bprint(self.classname, "\n");
1218
1219                 CheckRules_Player();
1220
1221                 if(self.button7)
1222                         PrintWelcomeMessage(self);
1223
1224                 if(cvar("g_lms") || !cvar("sv_spectate"))
1225                 if((time - self.jointime) <= cvar("welcome_message_time"))
1226                         PrintWelcomeMessage(self);
1227
1228                 if (intermission_running)
1229                 {
1230                         IntermissionThink ();   // otherwise a button could be missed between
1231                         return;                                 // the think tics
1232                 }
1233
1234                 if(time > self.teleport_time)
1235                 {
1236                         self.effects = self.effects - (self.effects & EF_NODRAW);
1237                         if(self.weaponentity)
1238                                 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1239                 }
1240
1241                 Nixnex_GiveCurrentWeapon();
1242                 UpdateSelectedPlayer();
1243
1244                 if (self.deadflag != DEAD_NO)
1245                 {
1246                         float button_pressed, force_respawn;
1247                         player_anim();
1248                         button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1249                         force_respawn = (cvar("g_lms") || cvar("g_forced_respawn"));
1250                         if (self.deadflag == DEAD_DYING)
1251                         {
1252                                 if(force_respawn)
1253                                         self.deadflag = DEAD_RESPAWNING;
1254                                 else if(!button_pressed)
1255                                         self.deadflag = DEAD_DEAD;
1256                         }
1257                         else if (self.deadflag == DEAD_DEAD)
1258                         {
1259                                 if(button_pressed)
1260                                         self.deadflag = DEAD_RESPAWNABLE;
1261                         }
1262                         else if (self.deadflag == DEAD_RESPAWNABLE)
1263                         {
1264                                 if(!button_pressed)
1265                                         self.deadflag = DEAD_RESPAWNING;
1266                         }
1267                         else if (self.deadflag == DEAD_RESPAWNING)
1268                         {
1269                                 if(time > self.death_time)
1270                                         respawn();
1271                         }
1272                         ShowRespawnCountdown();
1273                         return;
1274                 }
1275
1276                 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1277                 {
1278                         vector dist;
1279
1280                         // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1281                         dist = self.oldorigin - self.origin;
1282                         dist_z = 0;
1283                         self.lms_traveled_distance += fabs(vlen(dist));
1284
1285                         if(cvar("g_campaign"))
1286                         if(!campaign_bots_may_start)
1287                         {
1288                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1289                                 self.lms_traveled_distance = 0;
1290                         }
1291
1292                         if(time > self.lms_nextcheck)
1293                         {
1294                                 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1295                                 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1296                                 {
1297                                         centerprint(self, cvar_string("g_lms_campcheck_message"));
1298                                         // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1299                                         // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1300                                         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');
1301                                 }
1302                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1303                                 self.lms_traveled_distance = 0;
1304                         }
1305                 }
1306
1307                 if (self.button5 && !self.hook.state)
1308                 {
1309                         if (!self.crouch)
1310                         {
1311                                 self.crouch = TRUE;
1312                                 self.view_ofs = PL_CROUCH_VIEW_OFS;
1313                                 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1314                         }
1315                 }
1316                 else
1317                 {
1318                         if (self.crouch)
1319                         {
1320                                 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1321                                 if (!trace_startsolid)
1322                                 {
1323                                         self.crouch = FALSE;
1324                                         self.view_ofs = PL_VIEW_OFS;
1325                                         setsize (self, PL_MIN, PL_MAX);
1326                                 }
1327                         }
1328                 }
1329
1330                 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
1331                         local string defaultmodel;
1332                         defaultmodel = cvar_string("sv_defaultplayermodel");
1333
1334                         if (defaultmodel != self.model)
1335                         {
1336                                 m1 = self.mins;
1337                                 m2 = self.maxs;
1338                                 setmodel_lod (self, defaultmodel);
1339                                 setsize (self, m1, m2);
1340                         }
1341
1342                         if (self.skin != cvar("sv_defaultplayerskin"))
1343                                 self.skin = cvar("sv_defaultplayerskin");
1344                 } else {
1345                         if (self.playermodel != self.model)
1346                         {
1347                                 self.playermodel = CheckPlayerModel(self.playermodel);
1348                                 m1 = self.mins;
1349                                 m2 = self.maxs;
1350                                 setmodel_lod (self, self.playermodel);
1351                                 setsize (self, m1, m2);
1352                         }
1353
1354                         if(teams_matter)
1355                         {
1356                                 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1357                                         self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1358                         }
1359                         else
1360                         {
1361                                 if (self.skin != stof(self.playerskin))
1362                                         self.skin = stof(self.playerskin);
1363                         }
1364                 }
1365
1366                 GrapplingHookFrame();
1367
1368                 W_WeaponFrame();
1369
1370                 {
1371                         float zoomfactor, zoomspeed, zoomdir;
1372                         zoomfactor = self.cvar_cl_zoomfactor;
1373                         if(zoomfactor < 1 || zoomfactor > 16)
1374                                 zoomfactor = 2.5;
1375                         zoomspeed = self.cvar_cl_zoomspeed;
1376                         if(zoomspeed >= 0) // < 0 is instant zoom
1377                                 if(zoomspeed < 0.5 || zoomspeed > 16)
1378                                         zoomspeed = 3.5;
1379
1380                         zoomdir = self.button4;
1381                         if(self.button3)
1382                                 if(self.weapon == WEP_NEX)
1383                                         if(!cvar("g_minstagib"))
1384                                                 zoomdir = 1;
1385
1386                         if(zoomdir)
1387                                 self.has_zoomed = 1;
1388
1389                         if(self.has_zoomed)
1390                         {
1391                                 if(zoomspeed <= 0) // instant zoom
1392                                 {
1393                                         if(zoomdir)
1394                                                 self.viewzoom = 1 / zoomfactor;
1395                                         else
1396                                                 self.viewzoom = 1;
1397                                 }
1398                                 else
1399                                 {
1400                                         // geometric zoom would be:
1401                                         //   self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1402                                         // however, testing showed that arithmetic/harmonic zoom works better
1403                                         if(zoomdir)
1404                                                 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1405                                                 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1406                                                 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1407                                         else
1408                                                 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1409                                                 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1410                                                 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1411                                 }
1412                         }
1413                         else
1414                                 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1415                 }
1416
1417                 player_powerups();
1418                 player_regen();
1419                 player_anim();
1420
1421                 if (cvar("g_minstagib"))
1422                         minstagib_ammocheck();
1423
1424                 ctf_setstatus();
1425                 kh_setstatus();
1426
1427                 //self.angles_y=self.v_angle_y + 90;   // temp
1428
1429                 //if (TetrisPreFrame()) return;
1430         } else if(gameover) {
1431                 if (intermission_running)
1432                         IntermissionThink ();   // otherwise a button could be missed between
1433                 return;
1434         } else if(self.classname == "observer") {
1435
1436                 if (self.flags & FL_JUMPRELEASED) {
1437                         if (self.button2 && self.version == cvar("gameversion")) {
1438                                 self.welcomemessage_time = 0;
1439                                 self.flags = self.flags - FL_JUMPRELEASED;
1440                                 LeaveSpectatorMode();
1441                                 return;
1442                         } else if(self.button0 && self.version == cvar("gameversion")) {
1443                                 self.welcomemessage_time = 0;
1444                                 self.flags = self.flags - FL_JUMPRELEASED;
1445                                 if(SpectateNext() == 1) {
1446                                         self.classname = "spectator";
1447                                 }
1448                         }
1449                 } else {
1450                         if (!(self.button0 || self.button2)) {
1451                                 self.flags = self.flags | FL_JUMPRELEASED;
1452                         }
1453                 }
1454                 PrintWelcomeMessage(self);
1455         } else if(self.classname == "spectator") {
1456                 if (self.flags & FL_JUMPRELEASED) {
1457                         if (self.button2 && self.version == cvar("gameversion")) {
1458                                 self.welcomemessage_time = 0;
1459                                 self.flags = self.flags - FL_JUMPRELEASED;
1460                                 LeaveSpectatorMode();
1461                                 return;
1462                         } else if(self.button0) {
1463                                 self.welcomemessage_time = 0;
1464                                 self.flags = self.flags - FL_JUMPRELEASED;
1465                                 if(SpectateNext() == 1) {
1466                                         self.classname = "spectator";
1467                                 } else {
1468                                         self.classname = "observer";
1469                                         PutClientInServer();
1470                                 }
1471                         } else if (self.button3) {
1472                                 self.welcomemessage_time = 0;
1473                                 self.flags = self.flags - FL_JUMPRELEASED;
1474                                 self.classname = "observer";
1475                                 PutClientInServer();
1476                         } else {
1477                                 SpectateUpdate();
1478                         }
1479                 } else {
1480                         if (!(self.button0 || self.button3)) {
1481                                 self.flags = self.flags | FL_JUMPRELEASED;
1482                         }
1483                 }
1484                 PrintWelcomeMessage(self);
1485                 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1486         }
1487 }
1488
1489
1490 /*
1491 =============
1492 PlayerPostThink
1493
1494 Called every frame for each client after the physics are run
1495 =============
1496 */
1497 void PlayerPostThink (void)
1498 {
1499         // Savage: Check for nameless players
1500         if (strlen(self.netname) < 1) {
1501                 self.netname = "Player";
1502                 stuffcmd(self, "seta _cl_name Player\n");
1503         }
1504
1505         if(self.classname == "player") {
1506                 CheckRules_Player();
1507                 UpdateChatBubble();
1508                 UpdateTeamBubble();
1509                 if (self.impulse)
1510                         ImpulseCommands ();
1511                 if (intermission_running)
1512                         return;         // intermission or finale
1513
1514                 //PrintWelcomeMessage(self);
1515                 //if (TetrisPostFrame()) return;
1516         } else if (self.classname == "observer") {
1517                 //do nothing
1518         } else if (self.classname == "spectator") {
1519                 //do nothing
1520         }
1521         Arena_Warmup();
1522 }