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